Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript): typescript 4.5 support #3205

Merged
merged 12 commits into from Jan 27, 2022
Merged
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -123,7 +123,7 @@
"sizzle": "^2.3.6",
"terser": "5.6.1",
"tslib": "^2.1.0",
"typescript": "4.3.5",
"typescript": "4.5.4",
"webpack": "^4.46.0",
"ws": "7.4.6"
},
Expand Down
1 change: 1 addition & 0 deletions scripts/tsconfig.json
Expand Up @@ -15,6 +15,7 @@
"pretty": true,
"target": "es2017",
"incremental": false,
"useUnknownInCatchVariables": true
},
"include": [
"**/*.ts"
Expand Down
4 changes: 4 additions & 0 deletions src/client/client-patch-browser.ts
Expand Up @@ -21,6 +21,10 @@ export const patchBrowser = (): Promise<d.CustomElementsDefineOptions> => {

if (BUILD.profile && !performance.mark) {
// not all browsers support performance.mark/measure (Safari 10)
// because the mark/measure APIs are designed to write entries to a buffer in the browser that does not exist,
// simply stub the implementations out.
// TODO(STENCIL-323): Remove this patch when support for older browsers is removed (breaking)
// @ts-ignore
performance.mark = performance.measure = () => {
/*noop*/
};
Expand Down
1 change: 1 addition & 0 deletions src/compiler/sys/dependencies.json
Expand Up @@ -52,6 +52,7 @@
"compiler/lib.es2020.symbol.wellknown.d.ts",
"compiler/lib.es2021.d.ts",
"compiler/lib.es2021.full.d.ts",
"compiler/lib.es2021.intl.d.ts",
"compiler/lib.es2021.promise.d.ts",
"compiler/lib.es2021.string.d.ts",
"compiler/lib.es2021.weakref.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/compiler/sys/typescript/typescript-sys.ts
Expand Up @@ -83,6 +83,7 @@ export const patchTsSystemFileSystem = (

tsSys.readDirectory = (path, extensions, exclude, include, depth) => {
const cwd = stencilSys.getCurrentDirectory();
// TODO(STENCIL-344): Replace `matchFiles` with a function that is publicly exposed
return (ts as any).matchFiles(
path,
extensions,
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/transformers/style-imports.ts
Expand Up @@ -70,12 +70,13 @@ const updateEsmStyleImportPath = (
const orgImportPath = n.moduleSpecifier.text;
const importPath = getStyleImportPath(transformOpts, tsSourceFile, cmp, style, orgImportPath);

statements[i] = ts.updateImportDeclaration(
statements[i] = ts.factory.updateImportDeclaration(
n,
n.decorators,
n.modifiers,
n.importClause,
ts.createStringLiteral(importPath)
ts.factory.createStringLiteral(importPath),
undefined
);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/test/parse-props.spec.ts
Expand Up @@ -168,7 +168,7 @@ describe('parse props', () => {
location: 'global',
},
},
resolved: 'any',
resolved: 'Object',
original: 'Object',
},
docs: {
Expand Down
9 changes: 6 additions & 3 deletions src/compiler/transformers/transform-utils.ts
Expand Up @@ -595,9 +595,12 @@ export const createImportStatement = (importFnNames: string[], importPath: strin
importFnName = splt[0];
}

return ts.createImportSpecifier(
typeof importFnName === 'string' && importFnName !== importAs ? ts.createIdentifier(importFnName) : undefined,
ts.createIdentifier(importAs)
return ts.factory.createImportSpecifier(
false,
typeof importFnName === 'string' && importFnName !== importAs
? ts.factory.createIdentifier(importFnName)
: undefined,
ts.factory.createIdentifier(importAs)
);
});

Expand Down
14 changes: 9 additions & 5 deletions src/compiler/transformers/update-stencil-core-import.ts
Expand Up @@ -25,17 +25,21 @@ export const updateStencilCoreImports = (updatedCoreImportPath: string): ts.Tran
const keepImports = origImports.map((e) => e.getText()).filter((name) => KEEP_IMPORTS.has(name));

if (keepImports.length > 0) {
const newImport = ts.updateImportDeclaration(
const newImport = ts.factory.updateImportDeclaration(
s,
undefined,
undefined,
ts.createImportClause(
ts.factory.createImportClause(
false,
undefined,
ts.createNamedImports(
keepImports.map((name) => ts.createImportSpecifier(undefined, ts.createIdentifier(name)))
ts.factory.createNamedImports(
keepImports.map((name) =>
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier(name))
)
)
),
ts.createStringLiteral(updatedCoreImportPath)
ts.factory.createStringLiteral(updatedCoreImportPath),
undefined
);
newStatements.push(newImport);
}
Expand Down
4 changes: 2 additions & 2 deletions src/dev-server/dev-server-client/app-update.ts
Expand Up @@ -65,7 +65,7 @@ const appUpdate = (win: d.DevClientWindow, config: d.DevClientConfig, buildResul
// then let's refresh the page from the root of the server
appReset(win, config, () => {
logReload(`Initial load`);
win.location.reload(true);
win.location.reload();
});
return;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ const appHmr = (win: Window, hmr: d.HotModuleReplacement) => {
}

if (shouldWindowReload) {
win.location.reload(true);
win.location.reload();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dev-server/dev-server-client/client-web-socket.ts
Expand Up @@ -76,7 +76,7 @@ export const initClientWebSocket = (win: d.DevClientWindow, config: d.DevClientC
clearInterval(requestBuildResultsTmrId);

if (win['s-build-id'] !== msg.buildResults.buildId) {
win.location.reload(true);
win.location.reload();
}
win['s-build-id'] = msg.buildResults.buildId;
return;
Expand Down
2 changes: 2 additions & 0 deletions src/hydrate/runner/window-initialize.ts
Expand Up @@ -47,6 +47,8 @@ export function initializeWindow(
}

try {
// TODO(STENCIL-345) - Evaluate reconciling MockWindow, Window differences
// @ts-ignore
win.customElements = null;
} catch (e) {}

Expand Down
6 changes: 3 additions & 3 deletions src/mock-doc/custom-element-registry.ts
Expand Up @@ -81,14 +81,14 @@ export class MockCustomElementRegistry implements CustomElementRegistry {
}
}

whenDefined(tagName: string) {
whenDefined(tagName: string): Promise<CustomElementConstructor> {
tagName = tagName.toLowerCase();

if (this.__registry != null && this.__registry.has(tagName) === true) {
return Promise.resolve();
return Promise.resolve<CustomElementConstructor>(this.__registry.get(tagName).cstr);
}

return new Promise<void>((resolve) => {
return new Promise<CustomElementConstructor>((resolve) => {
if (this.__whenDefined == null) {
this.__whenDefined = new Map();
}
Expand Down
14 changes: 12 additions & 2 deletions src/mock-doc/performance.ts
Expand Up @@ -40,11 +40,21 @@ export class MockPerformance implements Performance {
return [] as any;
}

mark() {
// Stencil's implementation of `mark` is non-compliant with the `Performance` interface. Because Stencil will
// instantiate an instance of this class and may attempt to assign it to a variable of type `Performance`, the return
// type must match the `Performance` interface (rather than typing this function as returning `void` and ignoring the
// associated errors returned by the type checker)
// @ts-ignore
mark(): PerformanceMark {
//
}

measure() {
// Stencil's implementation of `measure` is non-compliant with the `Performance` interface. Because Stencil will
// instantiate an instance of this class and may attempt to assign it to a variable of type `Performance`, the return
// type must match the `Performance` interface (rather than typing this function as returning `void` and ignoring the
// associated errors returned by the type checker)
// @ts-ignore
measure(): PerformanceMeasure {
//
}

Expand Down
2 changes: 2 additions & 0 deletions src/mock-doc/window.ts
Expand Up @@ -802,6 +802,8 @@ export function cloneWindow(srcWin: Window, opts: { customElementProxy?: boolean

const clonedWin = new MockWindow(false);
if (!opts.customElementProxy) {
// TODO(STENCIL-345) - Evaluate reconciling MockWindow, Window differences
// @ts-ignore
srcWin.customElements = null;
}

Expand Down
1 change: 1 addition & 0 deletions src/runtime/test/tsconfig.json
Expand Up @@ -18,6 +18,7 @@
"noUnusedParameters": true,
"pretty": true,
"target": "es2017",
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"@stencil/core": ["../../index.ts"],
Expand Down
1 change: 1 addition & 0 deletions src/runtime/vdom/test/tsconfig.json
Expand Up @@ -17,6 +17,7 @@
"noUnusedParameters": true,
"pretty": true,
"target": "es2017",
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"@stencil/core": ["../../../index.ts"],
Expand Down
3 changes: 2 additions & 1 deletion src/testing/tsconfig.internal.json
Expand Up @@ -21,6 +21,7 @@
"noUnusedParameters": true,
"pretty": true,
"target": "es2017",
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"@stencil/core/cli": [
Expand All @@ -46,4 +47,4 @@
]
}
}
}
}
3 changes: 2 additions & 1 deletion test/browser-compile/tsconfig.json
Expand Up @@ -20,6 +20,7 @@
"noUnusedParameters": true,
"pretty": true,
"target": "es2017",
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"@stencil/core/testing": [
Expand All @@ -39,4 +40,4 @@
"include": [
"src"
]
}
}
3 changes: 2 additions & 1 deletion test/end-to-end/tsconfig.json
Expand Up @@ -21,6 +21,7 @@
"noUnusedParameters": true,
"pretty": true,
"target": "es2017",
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"@stencil/core": [
Expand All @@ -40,4 +41,4 @@
"include": [
"src"
]
}
}
1 change: 1 addition & 0 deletions test/hello-vdom/tsconfig.json
Expand Up @@ -19,6 +19,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"target": "es2017",
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"@stencil/core": ["../../internal"],
Expand Down
1 change: 1 addition & 0 deletions test/hello-world/tsconfig.parent.json
Expand Up @@ -19,6 +19,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"target": "es2017",
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"@stencil/core": ["../../internal"],
Expand Down
1 change: 1 addition & 0 deletions test/ionic-app/tsconfig.json
Expand Up @@ -12,6 +12,7 @@
"noUnusedParameters": true,
"jsx": "react",
"jsxFactory": "h",
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"@stencil/core": ["../../internal"],
Expand Down
1 change: 1 addition & 0 deletions test/jest-spec-runner/tsconfig.json
Expand Up @@ -19,6 +19,7 @@
"noUnusedParameters": true,
"pretty": true,
"target": "es2017",
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"@stencil/core": ["../../internal"],
Expand Down