Skip to content

Commit e1d4e66

Browse files
authored
feat(typescript): update to typescript 4.3.5 (#3103)
update typescript to v4.3.5 add type annotations to methods that have an implicit any type in TS 4.3 - for more information, see microsoft/TypeScript#26623 map TS 4.3+ `JSDocTagInfo` to `CompilerJsDocTagInfo` - for more information, see microsoft/TypeScript#43312 add type guard for `TestingSystem`. in TS 4.3, `Object.defineProperties` is now generic, and returns the same type `T` as it's first argument. adding a typeguard allows consumers of this method to ensure they're receiving a `TestingSystem` object enable `noImplicitOverride` compiler flag
1 parent 4b2018a commit e1d4e66

File tree

17 files changed

+161
-90
lines changed

17 files changed

+161
-90
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"sizzle": "^2.3.6",
121121
"terser": "5.6.1",
122122
"tslib": "^2.1.0",
123-
"typescript": "4.2.3",
123+
"typescript": "4.3.5",
124124
"webpack": "^4.46.0",
125125
"ws": "7.4.6"
126126
},

src/compiler/sys/dependencies.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
"compiler/lib.es2020.sharedmemory.d.ts",
5151
"compiler/lib.es2020.string.d.ts",
5252
"compiler/lib.es2020.symbol.wellknown.d.ts",
53+
"compiler/lib.es2021.d.ts",
54+
"compiler/lib.es2021.full.d.ts",
55+
"compiler/lib.es2021.promise.d.ts",
56+
"compiler/lib.es2021.string.d.ts",
57+
"compiler/lib.es2021.weakref.d.ts",
5358
"compiler/lib.es5.d.ts",
5459
"compiler/lib.es6.d.ts",
5560
"compiler/lib.esnext.d.ts",

src/compiler/transformers/decorators-to-static/method-decorator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createStaticGetter,
66
getAttributeTypeInfo,
77
isMemberPrivate,
8+
mapJSDocTagInfo,
89
serializeSymbol,
910
typeToString,
1011
validateReferences,
@@ -95,7 +96,7 @@ const parseMethodDecorator = (
9596
},
9697
docs: {
9798
text: ts.displayPartsToString(signature.getDocumentationComment(typeChecker)),
98-
tags: signature.getJsDocTags(),
99+
tags: mapJSDocTagInfo(signature.getJsDocTags()),
99100
},
100101
};
101102
validateReferences(diagnostics, methodMeta.complexType.references, method.type || method.name);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { mapJSDocTagInfo } from '../transform-utils';
2+
3+
describe('transform utils', () => {
4+
it('flattens TypeScript JSDocTagInfo to Stencil JSDocTagInfo', () => {
5+
// tags corresponds to the following JSDoc
6+
/*
7+
* @param foo the first parameter
8+
* @param bar
9+
* @returns
10+
* @see {@link https://example.com}
11+
*/
12+
const tags = [
13+
{
14+
name: 'param',
15+
text: [
16+
{ text: 'foo', kind: 'parameterName' },
17+
{ text: ' ', kind: 'space' },
18+
{ text: 'the first parameter', kind: 'text' },
19+
],
20+
},
21+
{ name: 'param', text: [{ text: 'bar', kind: 'text' }] },
22+
{ name: 'returns', text: undefined },
23+
{
24+
name: 'see',
25+
text: [
26+
{ text: '', kind: 'text' },
27+
{ text: '{@link ', kind: 'link' },
28+
{ text: 'https://example.com', kind: 'linkText' },
29+
{ text: '}', kind: 'link' },
30+
],
31+
},
32+
];
33+
34+
expect(mapJSDocTagInfo(tags)).toEqual([
35+
{ name: 'param', text: 'foo the first parameter' },
36+
{ name: 'param', text: 'bar' },
37+
{ name: 'returns', text: undefined },
38+
{ name: 'see', text: '{@link https://example.com}' },
39+
]);
40+
});
41+
});

src/compiler/transformers/transform-utils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,23 @@ export const serializeSymbol = (checker: ts.TypeChecker, symbol: ts.Symbol): d.C
515515
};
516516
}
517517
return {
518-
tags: symbol.getJsDocTags().map((tag) => ({ text: tag.text, name: tag.name })),
518+
tags: mapJSDocTagInfo(symbol.getJsDocTags()),
519519
text: ts.displayPartsToString(symbol.getDocumentationComment(checker)),
520520
};
521521
};
522522

523+
/**
524+
* Maps a TypeScript 4.3+ JSDocTagInfo to a flattened Stencil CompilerJsDocTagInfo.
525+
* @param tags A readonly array of JSDocTagInfo objects.
526+
* @returns An array of CompilerJsDocTagInfo objects.
527+
*/
528+
export const mapJSDocTagInfo = (tags: readonly ts.JSDocTagInfo[]): d.CompilerJsDocTagInfo[] => {
529+
// The text following a tag is split semantically by TS 4.3+, e.g. '@param foo the first parameter' ->
530+
// [{text: 'foo', kind: 'parameterName'}, {text: ' ', kind: 'space'}, {text: 'the first parameter', kind: 'text'}], so
531+
// we join the elements to reconstruct the text.
532+
return tags.map((tag) => ({ ...tag, text: tag.text?.map((part) => part.text).join('') }));
533+
};
534+
523535
export const serializeDocsSymbol = (checker: ts.TypeChecker, symbol: ts.Symbol) => {
524536
const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
525537
const set = new Set<string>();

src/mock-doc/comment-node.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ export class MockComment extends MockNode {
66
super(ownerDocument, NODE_TYPES.COMMENT_NODE, NODE_NAMES.COMMENT_NODE, data);
77
}
88

9-
cloneNode(_deep?: boolean) {
9+
override cloneNode(_deep?: boolean) {
1010
return new MockComment(null, this.nodeValue);
1111
}
1212

13-
get textContent() {
13+
override get textContent() {
1414
return this.nodeValue;
1515
}
1616

17-
set textContent(text) {
17+
override set textContent(text) {
1818
this.nodeValue = text;
1919
}
2020
}

src/mock-doc/document-fragment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class MockDocumentFragment extends MockHTMLElement {
1313
return getElementById(this, id);
1414
}
1515

16-
cloneNode(deep?: boolean) {
16+
override cloneNode(deep?: boolean) {
1717
const cloned = new MockDocumentFragment(null);
1818

1919
if (deep) {

src/mock-doc/document.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export class MockDocument extends MockHTMLElement {
4242
}
4343
}
4444

45-
get dir() {
45+
override get dir() {
4646
return this.documentElement.dir;
4747
}
48-
set dir(value: string) {
48+
override set dir(value: string) {
4949
this.documentElement.dir = value;
5050
}
5151

@@ -166,7 +166,7 @@ export class MockDocument extends MockHTMLElement {
166166
}
167167
}
168168

169-
appendChild(newNode: MockElement) {
169+
override appendChild(newNode: MockElement) {
170170
newNode.remove();
171171
newNode.parentNode = this;
172172
this.childNodes.push(newNode);
@@ -222,14 +222,14 @@ export class MockDocument extends MockHTMLElement {
222222
return getElementsByName(this, elmName.toLowerCase());
223223
}
224224

225-
get title() {
225+
override get title() {
226226
const title = this.head.childNodes.find((elm) => elm.nodeName === 'TITLE') as MockElement;
227227
if (title != null && typeof title.textContent === 'string') {
228228
return title.textContent.trim();
229229
}
230230
return '';
231231
}
232-
set title(value: string) {
232+
override set title(value: string) {
233233
const head = this.head;
234234
let title = head.childNodes.find((elm) => elm.nodeName === 'TITLE') as MockElement;
235235
if (title == null) {

src/mock-doc/element.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ export class MockImageElement extends MockHTMLElement {
107107
super(ownerDocument, 'img');
108108
}
109109

110-
get draggable() {
110+
override get draggable() {
111111
return this.getAttributeNS(null, 'draggable') !== 'false';
112112
}
113-
set draggable(value: boolean) {
113+
override set draggable(value: boolean) {
114114
this.setAttributeNS(null, 'draggable', value);
115115
}
116116

@@ -243,24 +243,24 @@ export class MockStyleElement extends MockHTMLElement {
243243
this.sheet = new MockCSSStyleSheet(this);
244244
}
245245

246-
get innerHTML() {
246+
override get innerHTML() {
247247
return getStyleElementText(this);
248248
}
249-
set innerHTML(value: string) {
249+
override set innerHTML(value: string) {
250250
setStyleElementText(this, value);
251251
}
252252

253-
get innerText() {
253+
override get innerText() {
254254
return getStyleElementText(this);
255255
}
256-
set innerText(value: string) {
256+
override set innerText(value: string) {
257257
setStyleElementText(this, value);
258258
}
259259

260-
get textContent() {
260+
override get textContent() {
261261
return getStyleElementText(this);
262262
}
263-
set textContent(value: string) {
263+
override set textContent(value: string) {
264264
setStyleElementText(this, value);
265265
}
266266
}
@@ -318,14 +318,14 @@ export class MockTemplateElement extends MockHTMLElement {
318318
this.content = new MockDocumentFragment(ownerDocument);
319319
}
320320

321-
get innerHTML() {
321+
override get innerHTML() {
322322
return this.content.innerHTML;
323323
}
324-
set innerHTML(html: string) {
324+
override set innerHTML(html: string) {
325325
this.content.innerHTML = html;
326326
}
327327

328-
cloneNode(deep?: boolean) {
328+
override cloneNode(deep?: boolean) {
329329
const cloned = new MockTemplateElement(null);
330330
cloned.attributes = cloneAttributes(this.attributes);
331331

0 commit comments

Comments
 (0)