PR feedback
- Cacheing the script target - Added missing return - Reworded error messages
This commit is contained in:
parent
85173a07d3
commit
2dffa5a601
5 changed files with 17 additions and 14 deletions
|
@ -104,6 +104,7 @@ namespace ts {
|
||||||
function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
||||||
let file: SourceFile;
|
let file: SourceFile;
|
||||||
let options: CompilerOptions;
|
let options: CompilerOptions;
|
||||||
|
let languageVersion: ScriptTarget;
|
||||||
let parent: Node;
|
let parent: Node;
|
||||||
let container: Node;
|
let container: Node;
|
||||||
let blockScopeContainer: Node;
|
let blockScopeContainer: Node;
|
||||||
|
@ -136,6 +137,7 @@ namespace ts {
|
||||||
function bindSourceFile(f: SourceFile, opts: CompilerOptions) {
|
function bindSourceFile(f: SourceFile, opts: CompilerOptions) {
|
||||||
file = f;
|
file = f;
|
||||||
options = opts;
|
options = opts;
|
||||||
|
languageVersion = getEmitScriptTarget(options);
|
||||||
inStrictMode = !!file.externalModuleIndicator;
|
inStrictMode = !!file.externalModuleIndicator;
|
||||||
classifiableNames = {};
|
classifiableNames = {};
|
||||||
|
|
||||||
|
@ -149,6 +151,7 @@ namespace ts {
|
||||||
|
|
||||||
file = undefined;
|
file = undefined;
|
||||||
options = undefined;
|
options = undefined;
|
||||||
|
languageVersion = undefined;
|
||||||
parent = undefined;
|
parent = undefined;
|
||||||
container = undefined;
|
container = undefined;
|
||||||
blockScopeContainer = undefined;
|
blockScopeContainer = undefined;
|
||||||
|
@ -1129,18 +1132,18 @@ namespace ts {
|
||||||
// Provide specialized messages to help the user understand why we think they're in
|
// Provide specialized messages to help the user understand why we think they're in
|
||||||
// strict mode.
|
// strict mode.
|
||||||
if (getContainingClass(node)) {
|
if (getContainingClass(node)) {
|
||||||
return Diagnostics.In_ES5_or_lower_function_declarations_are_not_allowed_in_block_scope_Class_definitions_are_automatically_in_strict_mode;
|
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES3_or_ES5_Class_definitions_are_automatically_in_strict_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file.externalModuleIndicator) {
|
if (file.externalModuleIndicator) {
|
||||||
return Diagnostics.In_ES5_or_lower_function_declarations_are_not_allowed_in_block_scope_Modules_are_automatically_in_strict_mode;
|
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES3_or_ES5_Modules_are_automatically_in_strict_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Diagnostics.In_ES5_or_lower_function_declarations_are_not_allowed_in_block_scope_in_strict_mode;
|
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES3_or_ES5;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkStrictModeFunctionDeclaration(node: FunctionDeclaration) {
|
function checkStrictModeFunctionDeclaration(node: FunctionDeclaration) {
|
||||||
if (getEmitScriptTarget(options) < ScriptTarget.ES6) {
|
if (languageVersion < ScriptTarget.ES6) {
|
||||||
// Report error if function is not top level function declaration
|
// Report error if function is not top level function declaration
|
||||||
if (blockScopeContainer.kind !== SyntaxKind.SourceFile &&
|
if (blockScopeContainer.kind !== SyntaxKind.SourceFile &&
|
||||||
blockScopeContainer.kind !== SyntaxKind.ModuleDeclaration &&
|
blockScopeContainer.kind !== SyntaxKind.ModuleDeclaration &&
|
||||||
|
@ -1671,7 +1674,7 @@ namespace ts {
|
||||||
checkStrictModeFunctionName(<FunctionDeclaration>node);
|
checkStrictModeFunctionName(<FunctionDeclaration>node);
|
||||||
if (inStrictMode) {
|
if (inStrictMode) {
|
||||||
checkStrictModeFunctionDeclaration(node);
|
checkStrictModeFunctionDeclaration(node);
|
||||||
bindBlockScopedDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
|
return bindBlockScopedDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
|
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
|
||||||
|
|
|
@ -811,15 +811,15 @@
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1249
|
"code": 1249
|
||||||
},
|
},
|
||||||
"In ES5 or lower, function declarations are not allowed in block scope in strict mode.": {
|
"Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1250
|
"code": 1250
|
||||||
},
|
},
|
||||||
"In ES5 or lower, function declarations are not allowed in block scope. Class definitions are automatically in strict mode.": {
|
"Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1251
|
"code": 1251
|
||||||
},
|
},
|
||||||
"In ES5 or lower, function declarations are not allowed in block scope. Modules are automatically in strict mode.": {
|
"Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Modules are automatically in strict mode.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1252
|
"code": 1252
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts(4,22): error TS1251: In ES5 or lower, function declarations are not allowed in block scope. Class definitions are automatically in strict mode.
|
tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts(4,22): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode.
|
||||||
tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts(7,9): error TS2304: Cannot find name 'foo'.
|
tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts(7,9): error TS2304: Cannot find name 'foo'.
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ tests/cases/compiler/blockScopedFunctionDeclarationInStrictClass.ts(7,9): error
|
||||||
if (true) {
|
if (true) {
|
||||||
function foo() { }
|
function foo() { }
|
||||||
~~~
|
~~~
|
||||||
!!! error TS1251: In ES5 or lower, function declarations are not allowed in block scope. Class definitions are automatically in strict mode.
|
!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode.
|
||||||
foo(); // ok
|
foo(); // ok
|
||||||
}
|
}
|
||||||
foo(); // not ok
|
foo(); // not ok
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts(2,14): error TS1252: In ES5 or lower, function declarations are not allowed in block scope. Modules are automatically in strict mode.
|
tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts(2,14): error TS1252: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Modules are automatically in strict mode.
|
||||||
tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts(6,10): error TS2304: Cannot find name 'foo'.
|
tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts(6,10): error TS2304: Cannot find name 'foo'.
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ tests/cases/compiler/blockScopedFunctionDeclarationInStrictModule.ts(6,10): erro
|
||||||
if (true) {
|
if (true) {
|
||||||
function foo() { }
|
function foo() { }
|
||||||
~~~
|
~~~
|
||||||
!!! error TS1252: In ES5 or lower, function declarations are not allowed in block scope. Modules are automatically in strict mode.
|
!!! error TS1252: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Modules are automatically in strict mode.
|
||||||
foo(); // ok
|
foo(); // ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
tests/cases/compiler/blockScopedFunctionDeclarationStrictES5.ts(3,14): error TS1250: In ES5 or lower, function declarations are not allowed in block scope in strict mode.
|
tests/cases/compiler/blockScopedFunctionDeclarationStrictES5.ts(3,14): error TS1250: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'.
|
||||||
tests/cases/compiler/blockScopedFunctionDeclarationStrictES5.ts(6,1): error TS2304: Cannot find name 'foo'.
|
tests/cases/compiler/blockScopedFunctionDeclarationStrictES5.ts(6,1): error TS2304: Cannot find name 'foo'.
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ tests/cases/compiler/blockScopedFunctionDeclarationStrictES5.ts(6,1): error TS23
|
||||||
if (true) {
|
if (true) {
|
||||||
function foo() { } // Error to declare function in block scope
|
function foo() { } // Error to declare function in block scope
|
||||||
~~~
|
~~~
|
||||||
!!! error TS1250: In ES5 or lower, function declarations are not allowed in block scope in strict mode.
|
!!! error TS1250: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'.
|
||||||
foo(); // This call should be ok
|
foo(); // This call should be ok
|
||||||
}
|
}
|
||||||
foo(); // Error to find name foo
|
foo(); // Error to find name foo
|
||||||
|
|
Loading…
Reference in a new issue