Skip to content

Commit 666c4be

Browse files
committed
Merge branch 'master' into referencesPrototypeSourceFile
2 parents 103fe5f + e8966ce commit 666c4be

File tree

271 files changed

+15652
-13128
lines changed

Some content is hidden

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

271 files changed

+15652
-13128
lines changed

src/compiler/builder.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,8 @@ namespace ts {
612612
*/
613613
function getProgramBuildInfo(state: Readonly<ReusableBuilderProgramState>, getCanonicalFileName: GetCanonicalFileName): ProgramBuildInfo | undefined {
614614
if (state.compilerOptions.outFile || state.compilerOptions.out) return undefined;
615-
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(getOutputPathForBuildInfo(state.compilerOptions)!, Debug.assertDefined(state.program).getCurrentDirectory()));
615+
const currentDirectory = Debug.assertDefined(state.program).getCurrentDirectory();
616+
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(getOutputPathForBuildInfo(state.compilerOptions)!, currentDirectory));
616617
const fileInfos: MapLike<BuilderState.FileInfo> = {};
617618
state.fileInfos.forEach((value, key) => {
618619
const signature = state.currentAffectedFilesSignatures && state.currentAffectedFilesSignatures.get(key);
@@ -621,7 +622,7 @@ namespace ts {
621622

622623
const result: ProgramBuildInfo = {
623624
fileInfos,
624-
options: convertToReusableCompilerOptions(state.compilerOptions, relativeToBuildInfo)
625+
options: convertToReusableCompilerOptions(state.compilerOptions, relativeToBuildInfoEnsuringAbsolutePath)
625626
};
626627
if (state.referencedMap) {
627628
const referencedMap: MapLike<string[]> = {};
@@ -661,6 +662,10 @@ namespace ts {
661662

662663
return result;
663664

665+
function relativeToBuildInfoEnsuringAbsolutePath(path: string) {
666+
return relativeToBuildInfo(getNormalizedAbsolutePath(path, currentDirectory));
667+
}
668+
664669
function relativeToBuildInfo(path: string) {
665670
return ensurePathIsNonModuleName(getRelativePathFromDirectory(buildInfoDirectory, path, getCanonicalFileName));
666671
}

src/compiler/checker.ts

+234-114
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

+26-8
Original file line numberDiff line numberDiff line change
@@ -2076,10 +2076,6 @@
20762076
"category": "Error",
20772077
"code": 2569
20782078
},
2079-
"Property '{0}' does not exist on type '{1}'. Did you forget to use 'await'?": {
2080-
"category": "Error",
2081-
"code": 2570
2082-
},
20832079
"Object is of type 'unknown'.": {
20842080
"category": "Error",
20852081
"code": 2571
@@ -4643,6 +4639,11 @@
46434639
"category": "Suggestion",
46444640
"code": 80006
46454641
},
4642+
"'await' has no effect on the type of this expression.": {
4643+
"category": "Suggestion",
4644+
"code": 80007
4645+
},
4646+
46464647
"Add missing 'super()' call": {
46474648
"category": "Message",
46484649
"code": 90001
@@ -5091,14 +5092,31 @@
50915092
"category": "Message",
50925093
"code": 95082
50935094
},
5095+
"Add 'await'": {
5096+
"category": "Message",
5097+
"code": 95083
5098+
},
5099+
"Add 'await' to initializer for '{0}'": {
5100+
"category": "Message",
5101+
"code": 95084
5102+
},
5103+
"Fix all expressions possibly missing 'await'": {
5104+
"category": "Message",
5105+
"code": 95085
5106+
},
5107+
"Remove unnecessary 'await'": {
5108+
"category": "Message",
5109+
"code": 95086
5110+
},
5111+
"Remove all unnecessary uses of 'await'": {
5112+
"category": "Message",
5113+
"code": 95087
5114+
},
5115+
50945116
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
50955117
"category": "Error",
50965118
"code": 18004
50975119
},
5098-
"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.": {
5099-
"category": "Error",
5100-
"code": 18005
5101-
},
51025120
"Classes may not have a field named 'constructor'.": {
51035121
"category": "Error",
51045122
"code": 18006

src/compiler/emitter.ts

+5-1
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

+1-1
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

+26-8
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

+1-1
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

+2-1
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

+28-3
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

+3-2
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

@@ -4762,7 +4763,7 @@ namespace ts {
47624763
UMD = 3,
47634764
System = 4,
47644765
ES2015 = 5,
4765-
ESNext = 6
4766+
ESNext = 99
47664767
}
47674768

47684769
export const enum JsxEmit {
@@ -4810,7 +4811,7 @@ namespace ts {
48104811
ES2018 = 5,
48114812
ES2019 = 6,
48124813
ES2020 = 7,
4813-
ESNext = 8,
4814+
ESNext = 99,
48144815
JSON = 100,
48154816
Latest = ESNext,
48164817
}

src/compiler/utilities.ts

+17
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);

0 commit comments

Comments
 (0)