Skip to content

Commit ef72e84

Browse files
committed
Merge branch 'master' of https://github.com/microsoft/TypeScript into feat/add-outlining-spans-for-object-destructuring-elements
2 parents 52d32e5 + 167f954 commit ef72e84

File tree

260 files changed

+4891
-1140
lines changed

Some content is hidden

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

260 files changed

+4891
-1140
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript",
33
"author": "Microsoft Corp.",
44
"homepage": "https://www.typescriptlang.org/",
5-
"version": "3.9.0",
5+
"version": "4.0.0",
66
"license": "Apache-2.0",
77
"description": "TypeScript is a language for application scale JavaScript development",
88
"keywords": [

src/compiler/binder.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,6 @@ namespace ts {
320320
}
321321
}
322322

323-
function setValueDeclaration(symbol: Symbol, node: Declaration): void {
324-
const { valueDeclaration } = symbol;
325-
if (!valueDeclaration ||
326-
(isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) ||
327-
(valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration))) {
328-
// other kinds of value declarations take precedence over modules and assignment declarations
329-
symbol.valueDeclaration = node;
330-
}
331-
}
332-
333323
// Should not be called on a declaration with a computed property name,
334324
// unless it is a well known Symbol.
335325
function getDeclarationName(node: Declaration): __String | undefined {

src/compiler/checker.ts

Lines changed: 190 additions & 56 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,28 @@ namespace ts {
844844
return to;
845845
}
846846

847+
/**
848+
* Combines two arrays, values, or undefineds into the smallest container that can accommodate the resulting set:
849+
*
850+
* ```
851+
* undefined -> undefined -> undefined
852+
* T -> undefined -> T
853+
* T -> T -> T[]
854+
* T[] -> undefined -> T[] (no-op)
855+
* T[] -> T -> T[] (append)
856+
* T[] -> T[] -> T[] (concatenate)
857+
* ```
858+
*/
859+
export function combine<T>(xs: T | readonly T[] | undefined, ys: T | readonly T[] | undefined): T | readonly T[] | undefined;
860+
export function combine<T>(xs: T | T[] | undefined, ys: T | T[] | undefined): T | T[] | undefined;
861+
export function combine<T>(xs: T | T[] | undefined, ys: T | T[] | undefined) {
862+
if (xs === undefined) return ys;
863+
if (ys === undefined) return xs;
864+
if (isArray(xs)) return isArray(ys) ? concatenate(xs, ys) : append(xs, ys);
865+
if (isArray(ys)) return append(ys, xs);
866+
return [xs, ys];
867+
}
868+
847869
/**
848870
* Gets the actual offset into an array for a relative offset. Negative offsets indicate a
849871
* position offset from the end of the array.

src/compiler/corePublic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ts {
22
// WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
33
// If changing the text in this section, be sure to test `configurePrerelease` too.
4-
export const versionMajorMinor = "3.9";
4+
export const versionMajorMinor = "4.0";
55
/** The version of the TypeScript compiler release */
66
export const version = `${versionMajorMinor}.0-dev`;
77

src/compiler/diagnosticMessages.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,11 +1477,11 @@
14771477
"category": "Error",
14781478
"code": 2371
14791479
},
1480-
"Parameter '{0}' cannot be referenced in its initializer.": {
1480+
"Parameter '{0}' cannot reference itself.": {
14811481
"category": "Error",
14821482
"code": 2372
14831483
},
1484-
"Initializer of parameter '{0}' cannot reference identifier '{1}' declared after it.": {
1484+
"Parameter '{0}' cannot reference identifier '{1}' declared after it.": {
14851485
"category": "Error",
14861486
"code": 2373
14871487
},
@@ -2963,6 +2963,10 @@
29632963
"category": "Error",
29642964
"code": 2789
29652965
},
2966+
"The operand of a 'delete' operator must be optional.": {
2967+
"category": "Error",
2968+
"code": 2790
2969+
},
29662970

29672971
"Import declaration '{0}' is using private name '{1}'.": {
29682972
"category": "Error",
@@ -4384,6 +4388,14 @@
43844388
"category": "Error",
43854389
"code": 6231
43864390
},
4391+
"Declaration augments declaration in another file. This cannot be serialized.": {
4392+
"category": "Error",
4393+
"code": 6232
4394+
},
4395+
"This is the declaration being augmented. Consider moving the augmenting declaration into the same file.": {
4396+
"category": "Error",
4397+
"code": 6233
4398+
},
43874399

43884400
"Projects to reference": {
43894401
"category": "Message",

src/compiler/emitter.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,16 +2366,10 @@ namespace ts {
23662366

23672367
function emitParenthesizedExpression(node: ParenthesizedExpression) {
23682368
const openParenPos = emitTokenWithComment(SyntaxKind.OpenParenToken, node.pos, writePunctuation, node);
2369-
const leadingNewlines = preserveSourceNewlines && getLeadingLineTerminatorCount(node, [node.expression], ListFormat.None);
2370-
if (leadingNewlines) {
2371-
writeLinesAndIndent(leadingNewlines, /*writeLinesIfNotIndenting*/ false);
2372-
}
2369+
const indented = writeLineSeparatorsAndIndentBefore(node.expression, node);
23732370
emitExpression(node.expression);
2374-
const trailingNewlines = preserveSourceNewlines && getClosingLineTerminatorCount(node, [node.expression], ListFormat.None);
2375-
if (trailingNewlines) {
2376-
writeLine(trailingNewlines);
2377-
}
2378-
decreaseIndentIf(leadingNewlines);
2371+
writeLineSeparatorsAfter(node.expression, node);
2372+
decreaseIndentIf(indented);
23792373
emitTokenWithComment(SyntaxKind.CloseParenToken, node.expression ? node.expression.end : openParenPos, writePunctuation, node);
23802374
}
23812375

@@ -3293,12 +3287,15 @@ namespace ts {
32933287
writePunctuation("<");
32943288

32953289
if (isJsxOpeningElement(node)) {
3290+
const indented = writeLineSeparatorsAndIndentBefore(node.tagName, node);
32963291
emitJsxTagName(node.tagName);
32973292
emitTypeArguments(node, node.typeArguments);
32983293
if (node.attributes.properties && node.attributes.properties.length > 0) {
32993294
writeSpace();
33003295
}
33013296
emit(node.attributes);
3297+
writeLineSeparatorsAfter(node.attributes, node);
3298+
decreaseIndentIf(indented);
33023299
}
33033300

33043301
writePunctuation(">");
@@ -4302,6 +4299,7 @@ namespace ts {
43024299
return getEffectiveLines(
43034300
includeComments => getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter(
43044301
firstChild.pos,
4302+
parentNode.pos,
43054303
currentSourceFile!,
43064304
includeComments));
43074305
}
@@ -4359,6 +4357,7 @@ namespace ts {
43594357
return getEffectiveLines(
43604358
includeComments => getLinesBetweenPositionAndNextNonWhitespaceCharacter(
43614359
lastChild.end,
4360+
parentNode.end,
43624361
currentSourceFile!,
43634362
includeComments));
43644363
}
@@ -4398,6 +4397,21 @@ namespace ts {
43984397
return lines;
43994398
}
44004399

4400+
function writeLineSeparatorsAndIndentBefore(node: Node, parent: Node): boolean {
4401+
const leadingNewlines = preserveSourceNewlines && getLeadingLineTerminatorCount(parent, [node], ListFormat.None);
4402+
if (leadingNewlines) {
4403+
writeLinesAndIndent(leadingNewlines, /*writeLinesIfNotIndenting*/ false);
4404+
}
4405+
return !!leadingNewlines;
4406+
}
4407+
4408+
function writeLineSeparatorsAfter(node: Node, parent: Node) {
4409+
const trailingNewlines = preserveSourceNewlines && getClosingLineTerminatorCount(parent, [node], ListFormat.None);
4410+
if (trailingNewlines) {
4411+
writeLine(trailingNewlines);
4412+
}
4413+
}
4414+
44014415
function synthesizedNodeStartsOnNewLine(node: Node, format: ListFormat) {
44024416
if (nodeIsSynthesized(node)) {
44034417
const startsOnNewLine = getStartsOnNewLine(node);

src/compiler/factory.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ namespace ts {
44
enableEmitNotification: noop,
55
enableSubstitution: noop,
66
endLexicalEnvironment: returnUndefined,
7-
getCompilerOptions: notImplemented,
7+
getCompilerOptions: () => ({}),
88
getEmitHost: notImplemented,
99
getEmitResolver: notImplemented,
10+
setLexicalEnvironmentFlags: noop,
11+
getLexicalEnvironmentFlags: () => 0,
1012
hoistFunctionDeclaration: noop,
1113
hoistVariableDeclaration: noop,
14+
addInitializationStatement: noop,
1215
isEmitNotificationEnabled: notImplemented,
1316
isSubstitutionEnabled: notImplemented,
1417
onEmitNode: noop,
@@ -852,13 +855,13 @@ namespace ts {
852855
* This function needs to be called whenever we transform the statement
853856
* list of a source file, namespace, or function-like body.
854857
*/
855-
export function addCustomPrologue(target: Statement[], source: readonly Statement[], statementOffset: number, visitor?: (node: Node) => VisitResult<Node>): number;
856-
export function addCustomPrologue(target: Statement[], source: readonly Statement[], statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>): number | undefined;
857-
export function addCustomPrologue(target: Statement[], source: readonly Statement[], statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>): number | undefined {
858+
export function addCustomPrologue(target: Statement[], source: readonly Statement[], statementOffset: number, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Node) => boolean): number;
859+
export function addCustomPrologue(target: Statement[], source: readonly Statement[], statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Node) => boolean): number | undefined;
860+
export function addCustomPrologue(target: Statement[], source: readonly Statement[], statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter: (node: Node) => boolean = returnTrue): number | undefined {
858861
const numStatements = source.length;
859862
while (statementOffset !== undefined && statementOffset < numStatements) {
860863
const statement = source[statementOffset];
861-
if (getEmitFlags(statement) & EmitFlags.CustomPrologue) {
864+
if (getEmitFlags(statement) & EmitFlags.CustomPrologue && filter(statement)) {
862865
append(target, visitor ? visitNode(statement, visitor, isStatement) : statement);
863866
}
864867
else {

src/compiler/transformer.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ namespace ts {
148148
const enabledSyntaxKindFeatures = new Array<SyntaxKindFeatureFlags>(SyntaxKind.Count);
149149
let lexicalEnvironmentVariableDeclarations: VariableDeclaration[];
150150
let lexicalEnvironmentFunctionDeclarations: FunctionDeclaration[];
151+
let lexicalEnvironmentStatements: Statement[];
152+
let lexicalEnvironmentFlags = LexicalEnvironmentFlags.None;
151153
let lexicalEnvironmentVariableDeclarationsStack: VariableDeclaration[][] = [];
152154
let lexicalEnvironmentFunctionDeclarationsStack: FunctionDeclaration[][] = [];
155+
let lexicalEnvironmentStatementsStack: Statement[][] = [];
156+
let lexicalEnvironmentFlagsStack: LexicalEnvironmentFlags[] = [];
153157
let lexicalEnvironmentStackOffset = 0;
154158
let lexicalEnvironmentSuspended = false;
155159
let emitHelpers: EmitHelper[] | undefined;
@@ -168,8 +172,11 @@ namespace ts {
168172
suspendLexicalEnvironment,
169173
resumeLexicalEnvironment,
170174
endLexicalEnvironment,
175+
setLexicalEnvironmentFlags,
176+
getLexicalEnvironmentFlags,
171177
hoistVariableDeclaration,
172178
hoistFunctionDeclaration,
179+
addInitializationStatement,
173180
requestEmitHelper,
174181
readEmitHelpers,
175182
enableSubstitution,
@@ -313,6 +320,9 @@ namespace ts {
313320
else {
314321
lexicalEnvironmentVariableDeclarations.push(decl);
315322
}
323+
if (lexicalEnvironmentFlags & LexicalEnvironmentFlags.InParameters) {
324+
lexicalEnvironmentFlags |= LexicalEnvironmentFlags.VariablesHoistedInParameters;
325+
}
316326
}
317327

318328
/**
@@ -321,6 +331,7 @@ namespace ts {
321331
function hoistFunctionDeclaration(func: FunctionDeclaration): void {
322332
Debug.assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization.");
323333
Debug.assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed.");
334+
setEmitFlags(func, EmitFlags.CustomPrologue);
324335
if (!lexicalEnvironmentFunctionDeclarations) {
325336
lexicalEnvironmentFunctionDeclarations = [func];
326337
}
@@ -329,6 +340,21 @@ namespace ts {
329340
}
330341
}
331342

343+
/**
344+
* Adds an initialization statement to the top of the lexical environment.
345+
*/
346+
function addInitializationStatement(node: Statement): void {
347+
Debug.assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization.");
348+
Debug.assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed.");
349+
setEmitFlags(node, EmitFlags.CustomPrologue);
350+
if (!lexicalEnvironmentStatements) {
351+
lexicalEnvironmentStatements = [node];
352+
}
353+
else {
354+
lexicalEnvironmentStatements.push(node);
355+
}
356+
}
357+
332358
/**
333359
* Starts a new lexical environment. Any existing hoisted variable or function declarations
334360
* are pushed onto a stack, and the related storage variables are reset.
@@ -344,9 +370,13 @@ namespace ts {
344370
// transformation.
345371
lexicalEnvironmentVariableDeclarationsStack[lexicalEnvironmentStackOffset] = lexicalEnvironmentVariableDeclarations;
346372
lexicalEnvironmentFunctionDeclarationsStack[lexicalEnvironmentStackOffset] = lexicalEnvironmentFunctionDeclarations;
373+
lexicalEnvironmentStatementsStack[lexicalEnvironmentStackOffset] = lexicalEnvironmentStatements;
374+
lexicalEnvironmentFlagsStack[lexicalEnvironmentStackOffset] = lexicalEnvironmentFlags;
347375
lexicalEnvironmentStackOffset++;
348376
lexicalEnvironmentVariableDeclarations = undefined!;
349377
lexicalEnvironmentFunctionDeclarations = undefined!;
378+
lexicalEnvironmentStatements = undefined!;
379+
lexicalEnvironmentFlags = LexicalEnvironmentFlags.None;
350380
}
351381

352382
/** Suspends the current lexical environment, usually after visiting a parameter list. */
@@ -375,7 +405,9 @@ namespace ts {
375405
Debug.assert(!lexicalEnvironmentSuspended, "Lexical environment is suspended.");
376406

377407
let statements: Statement[] | undefined;
378-
if (lexicalEnvironmentVariableDeclarations || lexicalEnvironmentFunctionDeclarations) {
408+
if (lexicalEnvironmentVariableDeclarations ||
409+
lexicalEnvironmentFunctionDeclarations ||
410+
lexicalEnvironmentStatements) {
379411
if (lexicalEnvironmentFunctionDeclarations) {
380412
statements = [...lexicalEnvironmentFunctionDeclarations];
381413
}
@@ -395,19 +427,42 @@ namespace ts {
395427
statements.push(statement);
396428
}
397429
}
430+
431+
if (lexicalEnvironmentStatements) {
432+
if (!statements) {
433+
statements = [...lexicalEnvironmentStatements];
434+
}
435+
else {
436+
statements = [...statements, ...lexicalEnvironmentStatements];
437+
}
438+
}
398439
}
399440

400441
// Restore the previous lexical environment.
401442
lexicalEnvironmentStackOffset--;
402443
lexicalEnvironmentVariableDeclarations = lexicalEnvironmentVariableDeclarationsStack[lexicalEnvironmentStackOffset];
403444
lexicalEnvironmentFunctionDeclarations = lexicalEnvironmentFunctionDeclarationsStack[lexicalEnvironmentStackOffset];
445+
lexicalEnvironmentStatements = lexicalEnvironmentStatementsStack[lexicalEnvironmentStackOffset];
446+
lexicalEnvironmentFlags = lexicalEnvironmentFlagsStack[lexicalEnvironmentStackOffset];
404447
if (lexicalEnvironmentStackOffset === 0) {
405448
lexicalEnvironmentVariableDeclarationsStack = [];
406449
lexicalEnvironmentFunctionDeclarationsStack = [];
450+
lexicalEnvironmentStatementsStack = [];
451+
lexicalEnvironmentFlagsStack = [];
407452
}
408453
return statements;
409454
}
410455

456+
function setLexicalEnvironmentFlags(flags: LexicalEnvironmentFlags, value: boolean): void {
457+
lexicalEnvironmentFlags = value ?
458+
lexicalEnvironmentFlags | flags :
459+
lexicalEnvironmentFlags & ~flags;
460+
}
461+
462+
function getLexicalEnvironmentFlags(): LexicalEnvironmentFlags {
463+
return lexicalEnvironmentFlags;
464+
}
465+
411466
function requestEmitHelper(helper: EmitHelper): void {
412467
Debug.assert(state > TransformationState.Uninitialized, "Cannot modify the transformation context during initialization.");
413468
Debug.assert(state < TransformationState.Completed, "Cannot modify the transformation context after transformation has completed.");

src/compiler/transformers/classFields.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ namespace ts {
606606
createConstructor(
607607
/*decorators*/ undefined,
608608
/*modifiers*/ undefined,
609-
parameters,
609+
parameters ?? [],
610610
body
611611
),
612612
constructor || node

src/compiler/transformers/declarations.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ namespace ts {
7676
reportLikelyUnsafeImportRequiredError,
7777
moduleResolverHost: host,
7878
trackReferencedAmbientModule,
79-
trackExternalModuleSymbolOfImportTypeNode
79+
trackExternalModuleSymbolOfImportTypeNode,
80+
reportNonlocalAugmentation
8081
};
8182
let errorNameNode: DeclarationName | undefined;
8283

@@ -190,6 +191,17 @@ namespace ts {
190191
}
191192
}
192193

194+
function reportNonlocalAugmentation(containingFile: SourceFile, parentSymbol: Symbol, symbol: Symbol) {
195+
const primaryDeclaration = find(parentSymbol.declarations, d => getSourceFileOfNode(d) === containingFile)!;
196+
const augmentingDeclarations = filter(symbol.declarations, d => getSourceFileOfNode(d) !== containingFile);
197+
for (const augmentations of augmentingDeclarations) {
198+
context.addDiagnostic(addRelatedInfo(
199+
createDiagnosticForNode(augmentations, Diagnostics.Declaration_augments_declaration_in_another_file_This_cannot_be_serialized),
200+
createDiagnosticForNode(primaryDeclaration, Diagnostics.This_is_the_declaration_being_augmented_Consider_moving_the_augmenting_declaration_into_the_same_file)
201+
));
202+
}
203+
}
204+
193205
function transformDeclarationsForJS(sourceFile: SourceFile, bundled?: boolean) {
194206
const oldDiag = getSymbolAccessibilityDiagnostic;
195207
getSymbolAccessibilityDiagnostic = (s) => ({

src/compiler/transformers/es2015.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,8 @@ namespace ts {
18531853
// ensureUseStrict is false because no new prologue-directive should be added.
18541854
// addStandardPrologue will put already-existing directives at the beginning of the target statement-array
18551855
statementOffset = addStandardPrologue(prologue, body.statements, /*ensureUseStrict*/ false);
1856+
statementOffset = addCustomPrologue(statements, body.statements, statementOffset, visitor, isHoistedFunction);
1857+
statementOffset = addCustomPrologue(statements, body.statements, statementOffset, visitor, isHoistedVariableStatement);
18561858
}
18571859

18581860
multiLine = addDefaultValueAssignmentsIfNeeded(statements, node) || multiLine;

0 commit comments

Comments
 (0)