Navigation Menu

Skip to content

Commit

Permalink
feat(typescript): update to typescript 4
Browse files Browse the repository at this point in the history
- Update to TypeScript 4 beta
- Move TypeScript to devDependencies
- Change nodeValue to getter/setter so it can be extended by E2EElement w/ typescript 4
  • Loading branch information
adamdbradley committed Aug 8, 2020
1 parent 5d15797 commit a274e11
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
15 changes: 12 additions & 3 deletions package-lock.json

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

4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
@@ -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) => {
Expand All @@ -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);
}
}
Expand Down
@@ -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';
Expand Down Expand Up @@ -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);

Expand Down
17 changes: 12 additions & 5 deletions src/mock-doc/node.ts
Expand Up @@ -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[];
Expand All @@ -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 = [];
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a274e11

Please sign in to comment.