Skip to content

Commit d4af185

Browse files
committed
Merge branch 'main' into v3.0.0-dev
2 parents 5557677 + ee1a295 commit d4af185

File tree

12 files changed

+1296
-55
lines changed

12 files changed

+1296
-55
lines changed

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/sys/stencil-sys.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,12 @@ export const createSystem = (c?: { logger?: Logger }) => {
289289
error: null,
290290
};
291291

292-
remoreDirSyncRecursive(p, opts, results);
292+
removeDirSyncRecursive(p, opts, results);
293293

294294
return results;
295295
};
296296

297-
const remoreDirSyncRecursive = (
297+
const removeDirSyncRecursive = (
298298
p: string,
299299
opts: CompilerSystemRemoveDirectoryOptions,
300300
results: CompilerSystemRemoveDirectoryResults
@@ -309,7 +309,7 @@ export const createSystem = (c?: { logger?: Logger }) => {
309309
const item = items.get(dirItemPath);
310310
if (item) {
311311
if (item.isDirectory) {
312-
remoreDirSyncRecursive(dirItemPath, opts, results);
312+
removeDirSyncRecursive(dirItemPath, opts, results);
313313
} else if (item.isFile) {
314314
const removeFileResults = removeFileSync(dirItemPath);
315315
if (removeFileResults.error) {

src/compiler/transformers/decorators-to-static/convert-decorators.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,20 @@ export const updateConstructor = (
414414
* @param classDeclaration a class declaration AST node
415415
* @returns whether this class has parents or not
416416
*/
417-
const needsSuper = (classDeclaration: ts.ClassDeclaration): boolean =>
418-
classDeclaration.heritageClauses && classDeclaration.heritageClauses.length > 0;
417+
const needsSuper = (classDeclaration: ts.ClassDeclaration): boolean => {
418+
const hasHeritageClauses = classDeclaration.heritageClauses && classDeclaration.heritageClauses.length > 0;
419+
420+
if (hasHeritageClauses) {
421+
// A {@link ts.SyntaxKind.HeritageClause} node may be for extending a
422+
// superclass _or_ for implementing an interface. We only want to add a
423+
// `super()` call to our synthetic constructor here in the case that there
424+
// is a superclass, so we can check for that situation by checking for the
425+
// presence of a heritage clause with the `.token` property set to
426+
// `ts.SyntaxKind.ExtendsKeyword`.
427+
return classDeclaration.heritageClauses.some((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword);
428+
}
429+
return false;
430+
};
419431

420432
/**
421433
* Create a statement with a call to `super()` suitable for including in the body of a constructor.

src/compiler/transformers/decorators-to-static/decorators-constants.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,7 @@ export const CLASS_DECORATORS_TO_REMOVE = ['Component'] as const;
88
* Decorators on class members that we remove as part of the compilation
99
* process
1010
*/
11-
export const MEMBER_DECORATORS_TO_REMOVE = [
12-
'Element',
13-
'Event',
14-
'Listen',
15-
'Method',
16-
'Prop',
17-
// TODO(STENCIL-591): Remove Deprecated Decorator Names
18-
'PropDidChange',
19-
// TODO(STENCIL-591): Remove Deprecated Decorator Names
20-
'PropWillChange',
21-
'State',
22-
'Watch',
23-
] as const;
11+
export const MEMBER_DECORATORS_TO_REMOVE = ['Element', 'Event', 'Listen', 'Method', 'Prop', 'State', 'Watch'] as const;
2412

2513
/**
2614
* Decorators whose 'decorees' we need to rewrite during compilation from

src/compiler/transformers/test/convert-decorators.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,33 @@ describe('convert-decorators', () => {
148148
}}`
149149
);
150150
});
151+
152+
it('should not add a super call to the constructor if necessary', () => {
153+
const t = transpileModule(`
154+
@Component({tag: 'cmp-a'})
155+
export class CmpA implements Foobar {
156+
@State() count: number = 0;
157+
}
158+
`);
159+
160+
expect(t.outputText).toBe(
161+
c`export class CmpA {
162+
constructor() {
163+
this.count = 0;
164+
}
165+
166+
static get is() {
167+
return "cmp-a";
168+
}
169+
170+
static get states() {
171+
return {
172+
"count": {}
173+
};
174+
}}`
175+
);
176+
});
177+
151178
it('should not convert `@Event` fields to constructor-initialization', () => {
152179
const t = transpileModule(`
153180
@Component({tag: 'cmp-a'})

src/compiler/transformers/test/parse-events.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ describe('parse events', () => {
105105
references: {
106106
Mode: {
107107
location: 'local',
108+
path: 'module.tsx',
108109
},
109110
},
110111
});

src/compiler/transformers/transform-utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,15 @@ const getTypeReferenceLocation = (typeName: string, tsNode: ts.Node): d.Componen
492492
if (isExported) {
493493
return {
494494
location: 'local',
495+
// If this is a local import, we know the path to the type
496+
// is the same as the current source file path
497+
//
498+
// We need to explicitly include the path here because
499+
// future logic for generating app types will use this resolved reference
500+
// to ensure that type name collisions do no occur in the output type
501+
// declaration file. If this path is omitted, the correct aliased type names
502+
// will not be used for component event definitions
503+
path: sourceFileObj.fileName,
495504
};
496505
}
497506

src/compiler/transpile/run-program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const runTsProgram = async (
6161
// Finalize components metadata
6262
buildCtx.moduleFiles = Array.from(compilerCtx.moduleMap.values());
6363
buildCtx.components = getComponentsFromModules(buildCtx.moduleFiles);
64+
6465
updateComponentBuildConditionals(compilerCtx.moduleMap, buildCtx.components);
6566
resolveComponentDependencies(buildCtx.components);
6667

src/compiler/types/generate-app-types.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { updateReferenceTypeImports } from './update-import-refs';
1919
* @returns `true` if the type declaration file written to disk has changed, `false` otherwise
2020
*/
2121
export const generateAppTypes = async (
22-
config: d.Config,
22+
config: d.ValidatedConfig,
2323
compilerCtx: d.CompilerCtx,
2424
buildCtx: d.BuildCtx,
2525
destination: string
@@ -44,7 +44,7 @@ export const generateAppTypes = async (
4444
);
4545
}
4646

47-
const writeResults = await compilerCtx.fs.writeFile(componentsDtsFilePath, componentTypesFileContent, {
47+
const writeResults = await compilerCtx.fs.writeFile(normalizePath(componentsDtsFilePath), componentTypesFileContent, {
4848
immediateWrite: true,
4949
});
5050
const hasComponentsDtsChanged = writeResults.changedContent;
@@ -92,29 +92,30 @@ const generateComponentTypesFile = (config: d.Config, buildCtx: d.BuildCtx, areT
9292
c.push(COMPONENTS_DTS_HEADER);
9393
c.push(`import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";`);
9494

95-
// write the import statements for our type declaration file
96-
c.push(
97-
...Object.keys(typeImportData).map((filePath) => {
98-
const typeData = typeImportData[filePath];
99-
let importFilePath: string;
100-
if (isAbsolute(filePath)) {
101-
importFilePath = normalizePath('./' + relative(config.srcDir, filePath)).replace(/\.(tsx|ts)$/, '');
102-
} else {
103-
importFilePath = filePath;
104-
}
105-
106-
return `import { ${typeData
107-
.sort(sortImportNames)
108-
.map((td) => {
109-
if (td.localName === td.importName) {
110-
return `${td.importName}`;
111-
} else {
112-
return `${td.localName} as ${td.importName}`;
113-
}
114-
})
115-
.join(`, `)} } from "${importFilePath}";`;
116-
})
117-
);
95+
// Map event type metadata to partial expressions (omitting import/export keywords)
96+
// e.g. { TestEvent } from '../path/to/event/test-event.interface';
97+
const expressions = Object.keys(typeImportData).map((filePath) => {
98+
const typeData = typeImportData[filePath];
99+
100+
let importFilePath = filePath;
101+
if (isAbsolute(filePath)) {
102+
importFilePath = normalizePath('./' + relative(config.srcDir, filePath)).replace(/\.(tsx|ts)$/, '');
103+
}
104+
105+
return `{ ${typeData
106+
.sort(sortImportNames)
107+
.map((td) => {
108+
if (td.localName === td.importName) {
109+
return `${td.importName}`;
110+
} else {
111+
return `${td.localName} as ${td.importName}`;
112+
}
113+
})
114+
.join(`, `)} } from "${importFilePath}";`;
115+
});
116+
117+
// Write all import and export statements for event types
118+
c.push(...expressions.map((ref) => `import ${ref}`), ...expressions.map((ref) => `export ${ref}`));
118119

119120
c.push(`export namespace Components {`);
120121
c.push(...modules.map((m) => `${m.component}`));

0 commit comments

Comments
 (0)