Skip to content

Commit a19307d

Browse files
committed
Merge branch 'master' into jsFileCompilation
2 parents 5ac6eb2 + bd84b84 commit a19307d

Some content is hidden

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

49 files changed

+2024
-1455
lines changed

scripts/tslint/preferConstRule.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ class PreferConstWalker extends Lint.RuleWalker {
8585

8686
visitBinaryExpression(node: ts.BinaryExpression) {
8787
if (isAssignmentOperator(node.operatorToken.kind)) {
88-
this.visitLHSExpressions(node.left);
88+
this.visitLeftHandSideExpression(node.left);
8989
}
9090
super.visitBinaryExpression(node);
9191
}
9292

93-
private visitLHSExpressions(node: ts.Expression) {
93+
private visitLeftHandSideExpression(node: ts.Expression) {
9494
while (node.kind === ts.SyntaxKind.ParenthesizedExpression) {
9595
node = (node as ts.ParenthesizedExpression).expression;
9696
}
@@ -106,18 +106,20 @@ class PreferConstWalker extends Lint.RuleWalker {
106106
if (node.kind === ts.SyntaxKind.ObjectLiteralExpression) {
107107
const pattern = node as ts.ObjectLiteralExpression;
108108
for (const element of pattern.properties) {
109-
if (element.name.kind === ts.SyntaxKind.Identifier) {
110-
this.markAssignment(element.name as ts.Identifier);
109+
const kind = element.kind;
110+
111+
if (kind === ts.SyntaxKind.ShorthandPropertyAssignment) {
112+
this.markAssignment((element as ts.ShorthandPropertyAssignment).name);
111113
}
112-
else if (isBindingPattern(element.name)) {
113-
this.visitBindingPatternIdentifiers(element.name as ts.BindingPattern);
114+
else if (kind === ts.SyntaxKind.PropertyAssignment) {
115+
this.visitLeftHandSideExpression((element as ts.PropertyAssignment).initializer);
114116
}
115117
}
116118
}
117119
else if (node.kind === ts.SyntaxKind.ArrayLiteralExpression) {
118120
const pattern = node as ts.ArrayLiteralExpression;
119121
for (const element of pattern.elements) {
120-
this.visitLHSExpressions(element);
122+
this.visitLeftHandSideExpression(element);
121123
}
122124
}
123125
}
@@ -145,7 +147,7 @@ class PreferConstWalker extends Lint.RuleWalker {
145147

146148
private visitAnyUnaryExpression(node: ts.PrefixUnaryExpression | ts.PostfixUnaryExpression) {
147149
if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator === ts.SyntaxKind.MinusMinusToken) {
148-
this.visitLHSExpressions(node.operand);
150+
this.visitLeftHandSideExpression(node.operand);
149151
}
150152
}
151153

@@ -211,12 +213,12 @@ class PreferConstWalker extends Lint.RuleWalker {
211213
}
212214
}
213215

214-
private collectNameIdentifiers(value: ts.VariableDeclaration, node: ts.Identifier | ts.BindingPattern, table: ts.Map<DeclarationUsages>) {
216+
private collectNameIdentifiers(declaration: ts.VariableDeclaration, node: ts.Identifier | ts.BindingPattern, table: ts.Map<DeclarationUsages>) {
215217
if (node.kind === ts.SyntaxKind.Identifier) {
216-
table[(node as ts.Identifier).text] = {declaration: value, usages: 0};
218+
table[(node as ts.Identifier).text] = { declaration, usages: 0 };
217219
}
218220
else {
219-
this.collectBindingPatternIdentifiers(value, node as ts.BindingPattern, table);
221+
this.collectBindingPatternIdentifiers(declaration, node as ts.BindingPattern, table);
220222
}
221223
}
222224

src/compiler/binder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ namespace ts {
139139
file.classifiableNames = classifiableNames;
140140
}
141141

142+
file = undefined;
143+
options = undefined;
142144
parent = undefined;
143145
container = undefined;
144146
blockScopeContainer = undefined;

src/compiler/checker.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -476,15 +476,41 @@ namespace ts {
476476
// Locals of a source file are not in scope (because they get merged into the global symbol table)
477477
if (location.locals && !isGlobalSourceFile(location)) {
478478
if (result = getSymbol(location.locals, name, meaning)) {
479-
// Type parameters of a function are in scope in the entire function declaration, including the parameter
480-
// list and return type. However, local types are only in scope in the function body.
481-
if (!(meaning & SymbolFlags.Type) ||
482-
!(result.flags & (SymbolFlags.Type & ~SymbolFlags.TypeParameter)) ||
483-
!isFunctionLike(location) ||
484-
lastLocation === (<FunctionLikeDeclaration>location).body) {
479+
let useResult = true;
480+
if (isFunctionLike(location) && lastLocation && lastLocation !== (<FunctionLikeDeclaration>location).body) {
481+
// symbol lookup restrictions for function-like declarations
482+
// - Type parameters of a function are in scope in the entire function declaration, including the parameter
483+
// list and return type. However, local types are only in scope in the function body.
484+
// - parameters are only in the scope of function body
485+
if (meaning & result.flags & SymbolFlags.Type) {
486+
useResult = result.flags & SymbolFlags.TypeParameter
487+
// type parameters are visible in parameter list, return type and type parameter list
488+
? lastLocation === (<FunctionLikeDeclaration>location).type ||
489+
lastLocation.kind === SyntaxKind.Parameter ||
490+
lastLocation.kind === SyntaxKind.TypeParameter
491+
// local types not visible outside the function body
492+
: false;
493+
}
494+
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.FunctionScopedVariable) {
495+
// parameters are visible only inside function body, parameter list and return type
496+
// technically for parameter list case here we might mix parameters and variables declared in function,
497+
// however it is detected separately when checking initializers of parameters
498+
// to make sure that they reference no variables declared after them.
499+
useResult =
500+
lastLocation.kind === SyntaxKind.Parameter ||
501+
(
502+
lastLocation === (<FunctionLikeDeclaration>location).type &&
503+
result.valueDeclaration.kind === SyntaxKind.Parameter
504+
);
505+
}
506+
}
507+
508+
if (useResult) {
485509
break loop;
486510
}
487-
result = undefined;
511+
else {
512+
result = undefined;
513+
}
488514
}
489515
}
490516
switch (location.kind) {
@@ -3829,7 +3855,13 @@ namespace ts {
38293855
let minArgumentCount = -1;
38303856
for (let i = 0, n = declaration.parameters.length; i < n; i++) {
38313857
const param = declaration.parameters[i];
3832-
parameters.push(param.symbol);
3858+
let paramSymbol = param.symbol;
3859+
// Include parameter symbol instead of property symbol in the signature
3860+
if (paramSymbol && !!(paramSymbol.flags & SymbolFlags.Property) && !isBindingPattern(param.name)) {
3861+
const resolvedSymbol = resolveName(param, paramSymbol.name, SymbolFlags.Value, undefined, undefined);
3862+
paramSymbol = resolvedSymbol;
3863+
}
3864+
parameters.push(paramSymbol);
38333865
if (param.type && param.type.kind === SyntaxKind.StringLiteral) {
38343866
hasStringLiterals = true;
38353867
}
@@ -9873,7 +9905,7 @@ namespace ts {
98739905
return type;
98749906
}
98759907

9876-
function checkFunctionExpressionOrObjectLiteralMethodBody(node: FunctionExpression | MethodDeclaration) {
9908+
function checkFunctionExpressionOrObjectLiteralMethodBody(node: ArrowFunction | FunctionExpression | MethodDeclaration) {
98779909
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
98789910

98799911
const isAsync = isAsyncFunctionLike(node);

src/compiler/emitter.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
484484
let decorateEmitted: boolean;
485485
let paramEmitted: boolean;
486486
let awaiterEmitted: boolean;
487-
let tempFlags: TempFlags;
487+
let tempFlags: TempFlags = 0;
488488
let tempVariables: Identifier[];
489489
let tempParameters: Identifier[];
490490
let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[];
@@ -553,17 +553,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
553553
return doEmit;
554554

555555
function doEmit(jsFilePath: string, sourceMapFilePath: string, sourceFiles: SourceFile[], isBundledEmit: boolean) {
556+
generatedNameSet = {};
557+
nodeToGeneratedName = [];
558+
isOwnFileEmit = !isBundledEmit;
559+
560+
if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) {
561+
initializeEmitterWithSourceMaps(jsFilePath, sourceMapFilePath, sourceFiles, isBundledEmit);
562+
}
563+
564+
// Emit helpers from all the files
565+
if (isBundledEmit && modulekind) {
566+
forEach(sourceFiles, emitEmitHelpers);
567+
}
568+
569+
// Do not call emit directly. It does not set the currentSourceFile.
570+
forEach(sourceFiles, emitSourceFile);
571+
572+
writeLine();
573+
writeEmittedFiles(writer.getText(), jsFilePath, /*writeByteOrderMark*/ compilerOptions.emitBOM);
574+
556575
// reset the state
557576
writer.reset();
558577
currentSourceFile = undefined;
559578
currentText = undefined;
560579
currentLineMap = undefined;
561580
exportFunctionForFile = undefined;
562-
generatedNameSet = {};
563-
nodeToGeneratedName = [];
581+
generatedNameSet = undefined;
582+
nodeToGeneratedName = undefined;
564583
computedPropertyNamesToGeneratedNames = undefined;
565584
convertedLoopState = undefined;
566-
567585
extendsEmitted = false;
568586
decorateEmitted = false;
569587
paramEmitted = false;
@@ -580,22 +598,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
580598
isEs6Module = false;
581599
renamedDependencies = undefined;
582600
isCurrentFileExternalModule = false;
583-
isOwnFileEmit = !isBundledEmit;
584-
585-
if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) {
586-
initializeEmitterWithSourceMaps(jsFilePath, sourceMapFilePath, sourceFiles, isBundledEmit);
587-
}
588-
589-
// Emit helpers from all the files
590-
if (isBundledEmit && modulekind) {
591-
forEach(sourceFiles, emitEmitHelpers);
592-
}
593-
594-
// Do not call emit directly. It does not set the currentSourceFile.
595-
forEach(sourceFiles, emitSourceFile);
596-
597-
writeLine();
598-
writeEmittedFiles(writer.getText(), jsFilePath, /*writeByteOrderMark*/ compilerOptions.emitBOM);
599601
}
600602

601603
function emitSourceFile(sourceFile: SourceFile): void {

0 commit comments

Comments
 (0)