From a274e1149c2da53b224bfba69e0a798c47920417 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 7 Aug 2020 19:14:28 -0500 Subject: [PATCH] feat(typescript): update to typescript 4 - Update to TypeScript 4 beta - Move TypeScript to devDependencies - Change nodeValue to getter/setter so it can be extended by E2EElement w/ typescript 4 --- package-lock.json | 15 ++++++++++++--- package.json | 4 +--- .../native-connected-callback.ts | 19 +++++++++++++++---- .../decorators-to-static/method-decorator.ts | 4 ++-- src/mock-doc/node.ts | 17 ++++++++++++----- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index e6451ca4ca2..8f349ffec1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4013,6 +4013,14 @@ "requires": { "typescript": ">=3.0.1", "yargs": "^15.3.1" + }, + "dependencies": { + "typescript": { + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", + "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", + "dev": true + } } }, "duplexify": { @@ -11518,9 +11526,10 @@ } }, "typescript": { - "version": "3.9.7", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", - "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==" + "version": "4.0.0-beta", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.0-beta.tgz", + "integrity": "sha512-d3s/CogGtB2uPZ2Z8ts6eoUxxyB9PH3R27/UrzvpthuOvpCg4FWWnBbBiqJ0K4eu6eTlgmLiqQkh2dquReJweA==", + "dev": true }, "uglify-js": { "version": "3.10.0", diff --git a/package.json b/package.json index 5eda8cb847c..1393b33c092 100644 --- a/package.json +++ b/package.json @@ -48,9 +48,6 @@ "test.prod": "npm run test.dist && npm run test.end-to-end && npm run test.jest && npm run test.karma && npm run test.sys.node && npm run test.testing", "test.watch": "jest --watch" }, - "dependencies": { - "typescript": "3.9.7" - }, "devDependencies": { "@rollup/plugin-commonjs": "12.0.0", "@rollup/plugin-json": "4.1.0", @@ -116,6 +113,7 @@ "sizzle": "^2.3.5", "terser": "4.8.0", "tslib": "^2.0.0", + "typescript": "4.0.0-beta", "webpack": "^4.44.0", "ws": "7.3.1" }, diff --git a/src/compiler/transformers/component-native/native-connected-callback.ts b/src/compiler/transformers/component-native/native-connected-callback.ts index abe525dbf90..33157f1c14b 100644 --- a/src/compiler/transformers/component-native/native-connected-callback.ts +++ b/src/compiler/transformers/component-native/native-connected-callback.ts @@ -1,4 +1,4 @@ -import * as d from '../../../declarations'; +import type * as d from '../../../declarations'; import ts from 'typescript'; export const addNativeConnectedCallback = (classMembers: ts.ClassElement[], cmp: d.ComponentCompilerMeta) => { @@ -13,13 +13,24 @@ export const addNativeConnectedCallback = (classMembers: ts.ClassElement[], cmp: return ts.isMethodDeclaration(classMember) && (classMember.name as any).escapedText === 'connectedCallback'; }) as ts.MethodDeclaration; - const prependBody = [fnCall]; if (connectedCallback != null) { // class already has a connectedCallback(), so update it - connectedCallback.body = ts.updateBlock(connectedCallback.body, [...prependBody, ...connectedCallback.body.statements]); + const callbackMethod = ts.createMethod( + undefined, + undefined, + undefined, + 'connectedCallback', + undefined, + undefined, + undefined, + undefined, + ts.createBlock([fnCall, ...connectedCallback.body.statements], true), + ); + const index = classMembers.indexOf(connectedCallback); + classMembers[index] = callbackMethod; } else { // class doesn't have a connectedCallback(), so add it - const callbackMethod = ts.createMethod(undefined, undefined, undefined, 'connectedCallback', undefined, undefined, undefined, undefined, ts.createBlock(prependBody, true)); + const callbackMethod = ts.createMethod(undefined, undefined, undefined, 'connectedCallback', undefined, undefined, undefined, undefined, ts.createBlock([fnCall], true)); classMembers.push(callbackMethod); } } diff --git a/src/compiler/transformers/decorators-to-static/method-decorator.ts b/src/compiler/transformers/decorators-to-static/method-decorator.ts index 3a32a26e073..d35fe166659 100644 --- a/src/compiler/transformers/decorators-to-static/method-decorator.ts +++ b/src/compiler/transformers/decorators-to-static/method-decorator.ts @@ -1,4 +1,4 @@ -import * as d from '../../../declarations'; +import type * as d from '../../../declarations'; import { augmentDiagnosticWithNode, buildError, buildWarn } from '@utils'; import { convertValueToLiteral, createStaticGetter, getAttributeTypeInfo, isMemberPrivate, serializeSymbol, typeToString, validateReferences } from '../transform-utils'; import { isDecoratorNamed } from './decorator-utils'; @@ -34,7 +34,7 @@ const parseMethodDecorator = (config: d.Config, diagnostics: d.Diagnostic[], tsS const flags = ts.TypeFormatFlags.WriteArrowStyleSignature | ts.TypeFormatFlags.NoTruncation; const signature = typeChecker.getSignatureFromDeclaration(method); const returnType = typeChecker.getReturnTypeOfSignature(signature); - const returnTypeNode = typeChecker.typeToTypeNode(returnType); + const returnTypeNode = typeChecker.typeToTypeNode(returnType, method, ts.NodeBuilderFlags.NoTruncation | ts.NodeBuilderFlags.NoTypeReduction); let returnString = typeToString(typeChecker, returnType); let signatureString = typeChecker.signatureToString(signature, method, flags, ts.SignatureKind.Call); diff --git a/src/mock-doc/node.ts b/src/mock-doc/node.ts index 0aa1cd5ee0d..9388299e11b 100644 --- a/src/mock-doc/node.ts +++ b/src/mock-doc/node.ts @@ -10,9 +10,9 @@ import { NON_ESCAPABLE_CONTENT, SerializeNodeToHtmlOptions, serializeNodeToHtml import { parseFragmentUtil } from './parse-util'; export class MockNode { + private _nodeValue: string; nodeName: string; nodeType: number; - nodeValue: string; ownerDocument: any; parentNode: MockNode; childNodes: MockNode[]; @@ -21,7 +21,7 @@ export class MockNode { this.ownerDocument = ownerDocument; this.nodeType = nodeType; this.nodeName = nodeName; - this.nodeValue = nodeValue; + this._nodeValue = nodeValue; this.parentNode = null; this.childNodes = []; } @@ -115,6 +115,13 @@ export class MockNode { return null; } + get nodeValue() { + return this._nodeValue; + } + set nodeValue(value: string) { + this._nodeValue = value; + } + get parentElement() { return ((this.parentNode as any) as MockElement) || null; } @@ -172,10 +179,10 @@ export class MockNode { } get textContent() { - return this.nodeValue; + return this._nodeValue; } set textContent(value: string) { - this.nodeValue = String(value); + this._nodeValue = String(value); } static ELEMENT_NODE = 1; @@ -327,7 +334,7 @@ export class MockElement extends MockNode { return { bottom: 0, height: 0, left: 0, right: 0, top: 0, width: 0, x: 0, y: 0 }; } - getRootNode(opts?: { composed?: boolean;[key: string]: any }) { + getRootNode(opts?: { composed?: boolean; [key: string]: any }) { const isComposed = opts != null && opts.composed === true; let node: Node = this as any;