Skip to content

Commit 742caba

Browse files
committed
Merge branch 'master' into fix32349
2 parents 6f637b0 + 9ec71c3 commit 742caba

File tree

245 files changed

+12996
-11917
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+12996
-11917
lines changed

src/compiler/checker.ts

Lines changed: 216 additions & 105 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4635,6 +4635,11 @@
46354635
"category": "Suggestion",
46364636
"code": 80006
46374637
},
4638+
"'await' has no effect on the type of this expression.": {
4639+
"category": "Suggestion",
4640+
"code": 80007
4641+
},
4642+
46384643
"Add missing 'super()' call": {
46394644
"category": "Message",
46404645
"code": 90001
@@ -5095,15 +5100,19 @@
50955100
"category": "Message",
50965101
"code": 95085
50975102
},
5103+
"Remove unnecessary 'await'": {
5104+
"category": "Message",
5105+
"code": 95086
5106+
},
5107+
"Remove all unnecessary uses of 'await'": {
5108+
"category": "Message",
5109+
"code": 95087
5110+
},
50985111

50995112
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
51005113
"category": "Error",
51015114
"code": 18004
51025115
},
5103-
"Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '[\"constructor\"]()' to write a method.": {
5104-
"category": "Error",
5105-
"code": 18005
5106-
},
51075116
"Classes may not have a field named 'constructor'.": {
51085117
"category": "Error",
51095118
"code": 18006

src/compiler/emitter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ namespace ts {
411411
}
412412
);
413413
if (emitOnlyDtsFiles && declarationTransform.transformed[0].kind === SyntaxKind.SourceFile) {
414-
const sourceFile = declarationTransform.transformed[0] as SourceFile;
414+
// Improved narrowing in master/3.6 makes this cast unnecessary, triggering a lint rule.
415+
// But at the same time, the LKG (3.5) necessitates it because it doesn’t narrow.
416+
// Once the LKG is updated to 3.6, this comment, the cast to `SourceFile`, and the
417+
// tslint directive can be all be removed.
418+
const sourceFile = declarationTransform.transformed[0] as SourceFile; // tslint:disable-line
415419
exportedModulesFromDeclarationEmit = sourceFile.exportedModulesFromDeclarationEmit;
416420
}
417421
}

src/compiler/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4701,7 +4701,7 @@ namespace ts {
47014701
}
47024702
}
47034703

4704-
function getLeftmostExpression(node: Expression, stopAtCallExpressions: boolean) {
4704+
export function getLeftmostExpression(node: Expression, stopAtCallExpressions: boolean) {
47054705
while (true) {
47064706
switch (node.kind) {
47074707
case SyntaxKind.PostfixUnaryExpression:

src/compiler/parser.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5656,12 +5656,27 @@ namespace ts {
56565656
return finishNode(node);
56575657
}
56585658

5659-
function parseConstructorDeclaration(node: ConstructorDeclaration): ConstructorDeclaration {
5660-
node.kind = SyntaxKind.Constructor;
5661-
parseExpected(SyntaxKind.ConstructorKeyword);
5662-
fillSignature(SyntaxKind.ColonToken, SignatureFlags.None, node);
5663-
node.body = parseFunctionBlockOrSemicolon(SignatureFlags.None, Diagnostics.or_expected);
5664-
return finishNode(node);
5659+
function parseConstructorName() {
5660+
if (token() === SyntaxKind.ConstructorKeyword) {
5661+
return parseExpected(SyntaxKind.ConstructorKeyword);
5662+
}
5663+
if (token() === SyntaxKind.StringLiteral && lookAhead(nextToken) === SyntaxKind.OpenParenToken) {
5664+
return tryParse(() => {
5665+
const literalNode = parseLiteralNode();
5666+
return literalNode.text === "constructor" ? literalNode : undefined;
5667+
});
5668+
}
5669+
}
5670+
5671+
function tryParseConstructorDeclaration(node: ConstructorDeclaration): ConstructorDeclaration | undefined {
5672+
return tryParse(() => {
5673+
if (parseConstructorName()) {
5674+
node.kind = SyntaxKind.Constructor;
5675+
fillSignature(SyntaxKind.ColonToken, SignatureFlags.None, node);
5676+
node.body = parseFunctionBlockOrSemicolon(SignatureFlags.None, Diagnostics.or_expected);
5677+
return finishNode(node);
5678+
}
5679+
});
56655680
}
56665681

56675682
function parseMethodDeclaration(node: MethodDeclaration, asteriskToken: AsteriskToken, diagnosticMessage?: DiagnosticMessage): MethodDeclaration {
@@ -5867,8 +5882,11 @@ namespace ts {
58675882
return parseAccessorDeclaration(<AccessorDeclaration>node, SyntaxKind.SetAccessor);
58685883
}
58695884

5870-
if (token() === SyntaxKind.ConstructorKeyword) {
5871-
return parseConstructorDeclaration(<ConstructorDeclaration>node);
5885+
if (token() === SyntaxKind.ConstructorKeyword || token() === SyntaxKind.StringLiteral) {
5886+
const constructorDeclaration = tryParseConstructorDeclaration(<ConstructorDeclaration>node);
5887+
if (constructorDeclaration) {
5888+
return constructorDeclaration;
5889+
}
58725890
}
58735891

58745892
if (isIndexSignature()) {

src/compiler/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ namespace ts {
197197
"|=": SyntaxKind.BarEqualsToken,
198198
"^=": SyntaxKind.CaretEqualsToken,
199199
"@": SyntaxKind.AtToken,
200+
"`": SyntaxKind.BacktickToken
200201
});
201202

202203
/*
@@ -298,7 +299,6 @@ namespace ts {
298299
}
299300

300301
const tokenStrings = makeReverseMap(textToToken);
301-
302302
export function tokenToString(t: SyntaxKind): string | undefined {
303303
return tokenStrings[t];
304304
}

src/compiler/transformers/es2017.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,11 @@ namespace ts {
775775
priority: 5,
776776
text: `
777777
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
778+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
778779
return new (P || (P = Promise))(function (resolve, reject) {
779780
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
780781
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
781-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
782+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
782783
step((generator = generator.apply(thisArg, _arguments || [])).next());
783784
});
784785
};`

src/compiler/transformers/es2018.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,39 @@ namespace ts {
229229
if (node.transformFlags & TransformFlags.ContainsObjectRestOrSpread) {
230230
// spread elements emit like so:
231231
// non-spread elements are chunked together into object literals, and then all are passed to __assign:
232-
// { a, ...o, b } => __assign({a}, o, {b});
232+
// { a, ...o, b } => __assign(__assign({a}, o), {b});
233233
// If the first element is a spread element, then the first argument to __assign is {}:
234-
// { ...o, a, b, ...o2 } => __assign({}, o, {a, b}, o2)
234+
// { ...o, a, b, ...o2 } => __assign(__assign(__assign({}, o), {a, b}), o2)
235+
//
236+
// We cannot call __assign with more than two elements, since any element could cause side effects. For
237+
// example:
238+
// var k = { a: 1, b: 2 };
239+
// var o = { a: 3, ...k, b: k.a++ };
240+
// // expected: { a: 1, b: 1 }
241+
// If we translate the above to `__assign({ a: 3 }, k, { b: k.a++ })`, the `k.a++` will evaluate before
242+
// `k` is spread and we end up with `{ a: 2, b: 1 }`.
243+
//
244+
// This also occurs for spread elements, not just property assignments:
245+
// var k = { a: 1, get b() { l = { z: 9 }; return 2; } };
246+
// var l = { c: 3 };
247+
// var o = { ...k, ...l };
248+
// // expected: { a: 1, b: 2, z: 9 }
249+
// If we translate the above to `__assign({}, k, l)`, the `l` will evaluate before `k` is spread and we
250+
// end up with `{ a: 1, b: 2, c: 3 }`
235251
const objects = chunkObjectLiteralElements(node.properties);
236252
if (objects.length && objects[0].kind !== SyntaxKind.ObjectLiteralExpression) {
237253
objects.unshift(createObjectLiteral());
238254
}
239-
return createAssignHelper(context, objects);
255+
let expression: Expression = objects[0];
256+
if (objects.length > 1) {
257+
for (let i = 1; i < objects.length; i++) {
258+
expression = createAssignHelper(context, [expression, objects[i]]);
259+
}
260+
return expression;
261+
}
262+
else {
263+
return createAssignHelper(context, objects);
264+
}
240265
}
241266
return visitEachChild(node, visitor, context);
242267
}

src/compiler/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,7 @@ namespace ts {
18821882
}
18831883

18841884
export interface JsxAttributes extends ObjectLiteralExpressionBase<JsxAttributeLike> {
1885+
kind: SyntaxKind.JsxAttributes;
18851886
parent: JsxOpeningLikeElement;
18861887
}
18871888

@@ -4759,7 +4760,7 @@ namespace ts {
47594760
UMD = 3,
47604761
System = 4,
47614762
ES2015 = 5,
4762-
ESNext = 6
4763+
ESNext = 99
47634764
}
47644765

47654766
export const enum JsxEmit {
@@ -4807,7 +4808,7 @@ namespace ts {
48074808
ES2018 = 5,
48084809
ES2019 = 6,
48094810
ES2020 = 7,
4810-
ESNext = 8,
4811+
ESNext = 99,
48114812
JSON = 100,
48124813
Latest = ESNext,
48134814
}

src/compiler/utilities.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3150,6 +3150,23 @@ namespace ts {
31503150
return s.replace(escapedCharsRegExp, getReplacement);
31513151
}
31523152

3153+
/**
3154+
* Strip off existed single quotes or double quotes from a given string
3155+
*
3156+
* @return non-quoted string
3157+
*/
3158+
export function stripQuotes(name: string) {
3159+
const length = name.length;
3160+
if (length >= 2 && name.charCodeAt(0) === name.charCodeAt(length - 1) && startsWithQuote(name)) {
3161+
return name.substring(1, length - 1);
3162+
}
3163+
return name;
3164+
}
3165+
3166+
export function startsWithQuote(name: string): boolean {
3167+
return isSingleOrDoubleQuote(name.charCodeAt(0));
3168+
}
3169+
31533170
function getReplacement(c: string, offset: number, input: string) {
31543171
if (c.charCodeAt(0) === CharacterCodes.nullCharacter) {
31553172
const lookAhead = input.charCodeAt(offset + c.length);
@@ -7468,7 +7485,7 @@ namespace ts {
74687485
export function getDirectoryPath(path: Path): Path;
74697486
/**
74707487
* Returns the path except for its basename. Semantics align with NodeJS's `path.dirname`
7471-
* except that we support URLs as well.
7488+
* except that we support URL's as well.
74727489
*
74737490
* ```ts
74747491
* getDirectoryPath("/path/to/file.ext") === "/path/to"

0 commit comments

Comments
 (0)