Merge pull request #25633 from Kingwl/strictParameter
add use strict and simple parameter check
This commit is contained in:
commit
ed70d4887a
|
@ -28822,11 +28822,40 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function getNonSimpleParameters(parameters: ReadonlyArray<ParameterDeclaration>): ReadonlyArray<ParameterDeclaration> {
|
||||
return filter(parameters, parameter => !!parameter.initializer || isBindingPattern(parameter.name) || isRestParameter(parameter));
|
||||
}
|
||||
|
||||
function checkGrammarForUseStrictSimpleParameterList(node: FunctionLikeDeclaration): boolean {
|
||||
if (languageVersion >= ScriptTarget.ES2016) {
|
||||
const useStrictDirective = node.body && isBlock(node.body) && findUseStrictPrologue(node.body.statements);
|
||||
if (useStrictDirective) {
|
||||
const nonSimpleParameters = getNonSimpleParameters(node.parameters);
|
||||
if (length(nonSimpleParameters)) {
|
||||
forEach(nonSimpleParameters, parameter => {
|
||||
addRelatedInfo(
|
||||
error(parameter, Diagnostics.This_parameter_is_not_allowed_with_use_strict_directive),
|
||||
createDiagnosticForNode(useStrictDirective, Diagnostics.use_strict_directive_used_here)
|
||||
);
|
||||
});
|
||||
|
||||
const diagnostics = nonSimpleParameters.map((parameter, index) => (
|
||||
index === 0 ? createDiagnosticForNode(parameter, Diagnostics.Non_simple_parameter_declared_here) : createDiagnosticForNode(parameter, Diagnostics.and_here)
|
||||
)) as [DiagnosticWithLocation, ...DiagnosticWithLocation[]];
|
||||
addRelatedInfo(error(useStrictDirective, Diagnostics.use_strict_directive_cannot_be_used_with_non_simple_parameter_list), ...diagnostics);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration | MethodSignature): boolean {
|
||||
// Prevent cascading error by short-circuit
|
||||
const file = getSourceFileOfNode(node);
|
||||
return checkGrammarDecoratorsAndModifiers(node) || checkGrammarTypeParameterList(node.typeParameters, file) ||
|
||||
checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
|
||||
checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file) ||
|
||||
(isFunctionLikeDeclaration(node) && checkGrammarForUseStrictSimpleParameterList(node));
|
||||
}
|
||||
|
||||
function checkGrammarClassLikeDeclaration(node: ClassLikeDeclaration): boolean {
|
||||
|
|
|
@ -991,6 +991,22 @@
|
|||
"category": "Error",
|
||||
"code": 1345
|
||||
},
|
||||
"This parameter is not allowed with 'use strict' directive.": {
|
||||
"category": "Error",
|
||||
"code": 1346
|
||||
},
|
||||
"'use strict' directive cannot be used with non-simple parameter list.": {
|
||||
"category": "Error",
|
||||
"code": 1347
|
||||
},
|
||||
"Non-simple parameter declared here.": {
|
||||
"category": "Error",
|
||||
"code": 1348
|
||||
},
|
||||
"'use strict' directive used here.": {
|
||||
"category": "Error",
|
||||
"code": 1349
|
||||
},
|
||||
|
||||
"Duplicate identifier '{0}'.": {
|
||||
"category": "Error",
|
||||
|
|
|
@ -3894,6 +3894,20 @@ namespace ts {
|
|||
return statementOffset;
|
||||
}
|
||||
|
||||
export function findUseStrictPrologue(statements: ReadonlyArray<Statement>): Statement | undefined {
|
||||
for (const statement of statements) {
|
||||
if (isPrologueDirective(statement)) {
|
||||
if (isUseStrictPrologue(statement)) {
|
||||
return statement;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function startsWithUseStrict(statements: ReadonlyArray<Statement>) {
|
||||
const firstStatement = firstOrUndefined(statements);
|
||||
return firstStatement !== undefined
|
||||
|
@ -3907,18 +3921,7 @@ namespace ts {
|
|||
* @param statements An array of statements
|
||||
*/
|
||||
export function ensureUseStrict(statements: NodeArray<Statement>): NodeArray<Statement> {
|
||||
let foundUseStrict = false;
|
||||
for (const statement of statements) {
|
||||
if (isPrologueDirective(statement)) {
|
||||
if (isUseStrictPrologue(statement as ExpressionStatement)) {
|
||||
foundUseStrict = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
const foundUseStrict = findUseStrictPrologue(statements);
|
||||
|
||||
if (!foundUseStrict) {
|
||||
return setTextRange(
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
//// [functionWithUseStrictAndSimpleParameterList.ts]
|
||||
function a(a = 10) {
|
||||
"use strict";
|
||||
}
|
||||
|
||||
export var foo = 10;
|
||||
function b(a = 10) {
|
||||
}
|
||||
|
||||
function container() {
|
||||
"use strict";
|
||||
function f(a = 10) {
|
||||
}
|
||||
}
|
||||
|
||||
function rest(...args: any[]) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function rest1(a = 1, ...args) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function paramDefault(param = 1) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function objectBindingPattern({foo}: any) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function arrayBindingPattern([foo]: any[]) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
const c = 1;
|
||||
"use strict";
|
||||
}
|
||||
|
||||
|
||||
//// [functionWithUseStrictAndSimpleParameterList.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
function a(a) {
|
||||
"use strict";
|
||||
if (a === void 0) { a = 10; }
|
||||
}
|
||||
exports.foo = 10;
|
||||
function b(a) {
|
||||
if (a === void 0) { a = 10; }
|
||||
}
|
||||
function container() {
|
||||
"use strict";
|
||||
function f(a) {
|
||||
if (a === void 0) { a = 10; }
|
||||
}
|
||||
}
|
||||
function rest() {
|
||||
'use strict';
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
}
|
||||
function rest1(a) {
|
||||
'use strict';
|
||||
if (a === void 0) { a = 1; }
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
}
|
||||
function paramDefault(param) {
|
||||
'use strict';
|
||||
if (param === void 0) { param = 1; }
|
||||
}
|
||||
function objectBindingPattern(_a) {
|
||||
'use strict';
|
||||
var foo = _a.foo;
|
||||
}
|
||||
function arrayBindingPattern(_a) {
|
||||
'use strict';
|
||||
var foo = _a[0];
|
||||
}
|
||||
function manyParameter(a, b) {
|
||||
"use strict";
|
||||
if (a === void 0) { a = 10; }
|
||||
if (b === void 0) { b = 20; }
|
||||
}
|
||||
function manyPrologue(a, b) {
|
||||
"foo";
|
||||
"use strict";
|
||||
if (a === void 0) { a = 10; }
|
||||
if (b === void 0) { b = 20; }
|
||||
}
|
||||
function invalidPrologue(a, b) {
|
||||
"foo";
|
||||
if (a === void 0) { a = 10; }
|
||||
if (b === void 0) { b = 20; }
|
||||
var c = 1;
|
||||
"use strict";
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
=== tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList.ts ===
|
||||
function a(a = 10) {
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList.ts, 0, 11))
|
||||
|
||||
"use strict";
|
||||
}
|
||||
|
||||
export var foo = 10;
|
||||
>foo : Symbol(foo, Decl(functionWithUseStrictAndSimpleParameterList.ts, 4, 10))
|
||||
|
||||
function b(a = 10) {
|
||||
>b : Symbol(b, Decl(functionWithUseStrictAndSimpleParameterList.ts, 4, 20))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList.ts, 5, 11))
|
||||
}
|
||||
|
||||
function container() {
|
||||
>container : Symbol(container, Decl(functionWithUseStrictAndSimpleParameterList.ts, 6, 1))
|
||||
|
||||
"use strict";
|
||||
function f(a = 10) {
|
||||
>f : Symbol(f, Decl(functionWithUseStrictAndSimpleParameterList.ts, 9, 17))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList.ts, 10, 15))
|
||||
}
|
||||
}
|
||||
|
||||
function rest(...args: any[]) {
|
||||
>rest : Symbol(rest, Decl(functionWithUseStrictAndSimpleParameterList.ts, 12, 1))
|
||||
>args : Symbol(args, Decl(functionWithUseStrictAndSimpleParameterList.ts, 14, 14))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function rest1(a = 1, ...args) {
|
||||
>rest1 : Symbol(rest1, Decl(functionWithUseStrictAndSimpleParameterList.ts, 16, 1))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList.ts, 18, 15))
|
||||
>args : Symbol(args, Decl(functionWithUseStrictAndSimpleParameterList.ts, 18, 21))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function paramDefault(param = 1) {
|
||||
>paramDefault : Symbol(paramDefault, Decl(functionWithUseStrictAndSimpleParameterList.ts, 20, 1))
|
||||
>param : Symbol(param, Decl(functionWithUseStrictAndSimpleParameterList.ts, 22, 22))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function objectBindingPattern({foo}: any) {
|
||||
>objectBindingPattern : Symbol(objectBindingPattern, Decl(functionWithUseStrictAndSimpleParameterList.ts, 24, 1))
|
||||
>foo : Symbol(foo, Decl(functionWithUseStrictAndSimpleParameterList.ts, 26, 31))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function arrayBindingPattern([foo]: any[]) {
|
||||
>arrayBindingPattern : Symbol(arrayBindingPattern, Decl(functionWithUseStrictAndSimpleParameterList.ts, 28, 1))
|
||||
>foo : Symbol(foo, Decl(functionWithUseStrictAndSimpleParameterList.ts, 30, 30))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
>manyParameter : Symbol(manyParameter, Decl(functionWithUseStrictAndSimpleParameterList.ts, 32, 1))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList.ts, 34, 23))
|
||||
>b : Symbol(b, Decl(functionWithUseStrictAndSimpleParameterList.ts, 34, 30))
|
||||
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
>manyPrologue : Symbol(manyPrologue, Decl(functionWithUseStrictAndSimpleParameterList.ts, 36, 1))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList.ts, 38, 22))
|
||||
>b : Symbol(b, Decl(functionWithUseStrictAndSimpleParameterList.ts, 38, 29))
|
||||
|
||||
"foo";
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
>invalidPrologue : Symbol(invalidPrologue, Decl(functionWithUseStrictAndSimpleParameterList.ts, 41, 1))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList.ts, 43, 25))
|
||||
>b : Symbol(b, Decl(functionWithUseStrictAndSimpleParameterList.ts, 43, 32))
|
||||
|
||||
"foo";
|
||||
const c = 1;
|
||||
>c : Symbol(c, Decl(functionWithUseStrictAndSimpleParameterList.ts, 45, 9))
|
||||
|
||||
"use strict";
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
=== tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList.ts ===
|
||||
function a(a = 10) {
|
||||
>a : (a?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
}
|
||||
|
||||
export var foo = 10;
|
||||
>foo : number
|
||||
>10 : 10
|
||||
|
||||
function b(a = 10) {
|
||||
>b : (a?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
}
|
||||
|
||||
function container() {
|
||||
>container : () => void
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
|
||||
function f(a = 10) {
|
||||
>f : (a?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
}
|
||||
}
|
||||
|
||||
function rest(...args: any[]) {
|
||||
>rest : (...args: any[]) => void
|
||||
>args : any[]
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function rest1(a = 1, ...args) {
|
||||
>rest1 : (a?: number, ...args: any[]) => void
|
||||
>a : number
|
||||
>1 : 1
|
||||
>args : any[]
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function paramDefault(param = 1) {
|
||||
>paramDefault : (param?: number) => void
|
||||
>param : number
|
||||
>1 : 1
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function objectBindingPattern({foo}: any) {
|
||||
>objectBindingPattern : ({ foo }: any) => void
|
||||
>foo : any
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function arrayBindingPattern([foo]: any[]) {
|
||||
>arrayBindingPattern : ([foo]: any[]) => void
|
||||
>foo : any
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
>manyParameter : (a?: number, b?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
>b : number
|
||||
>20 : 20
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
}
|
||||
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
>manyPrologue : (a?: number, b?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
>b : number
|
||||
>20 : 20
|
||||
|
||||
"foo";
|
||||
>"foo" : "foo"
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
}
|
||||
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
>invalidPrologue : (a?: number, b?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
>b : number
|
||||
>20 : 20
|
||||
|
||||
"foo";
|
||||
>"foo" : "foo"
|
||||
|
||||
const c = 1;
|
||||
>c : 1
|
||||
>1 : 1
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(1,12): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(2,5): error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(15,15): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(16,5): error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(19,16): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(19,23): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(20,5): error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(23,23): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(24,5): error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(27,31): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(28,5): error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(31,30): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(32,5): error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(35,24): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(35,32): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(36,5): error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(39,23): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(39,31): error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts(41,5): error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
|
||||
|
||||
==== tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts (19 errors) ====
|
||||
function a(a = 10) {
|
||||
~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:2:5: 'use strict' directive used here.
|
||||
"use strict";
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
!!! related TS1348 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:1:12: Non-simple parameter declared here.
|
||||
}
|
||||
|
||||
export var foo = 10;
|
||||
function b(a = 10) {
|
||||
}
|
||||
|
||||
function container() {
|
||||
"use strict";
|
||||
function f(a = 10) {
|
||||
}
|
||||
}
|
||||
|
||||
function rest(...args: any[]) {
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:16:5: 'use strict' directive used here.
|
||||
'use strict';
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
!!! related TS1348 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:15:15: Non-simple parameter declared here.
|
||||
}
|
||||
|
||||
function rest1(a = 1, ...args) {
|
||||
~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:20:5: 'use strict' directive used here.
|
||||
~~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:20:5: 'use strict' directive used here.
|
||||
'use strict';
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
!!! related TS1348 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:19:16: Non-simple parameter declared here.
|
||||
!!! related TS6204 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:19:23: and here.
|
||||
}
|
||||
|
||||
function paramDefault(param = 1) {
|
||||
~~~~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:24:5: 'use strict' directive used here.
|
||||
'use strict';
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
!!! related TS1348 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:23:23: Non-simple parameter declared here.
|
||||
}
|
||||
|
||||
function objectBindingPattern({foo}: any) {
|
||||
~~~~~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:28:5: 'use strict' directive used here.
|
||||
'use strict';
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
!!! related TS1348 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:27:31: Non-simple parameter declared here.
|
||||
}
|
||||
|
||||
function arrayBindingPattern([foo]: any[]) {
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:32:5: 'use strict' directive used here.
|
||||
'use strict';
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
!!! related TS1348 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:31:30: Non-simple parameter declared here.
|
||||
}
|
||||
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:36:5: 'use strict' directive used here.
|
||||
~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:36:5: 'use strict' directive used here.
|
||||
"use strict";
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
!!! related TS1348 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:35:24: Non-simple parameter declared here.
|
||||
!!! related TS6204 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:35:32: and here.
|
||||
}
|
||||
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:41:5: 'use strict' directive used here.
|
||||
~~~~~~
|
||||
!!! error TS1346: This parameter is not allowed with 'use strict' directive.
|
||||
!!! related TS1349 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:41:5: 'use strict' directive used here.
|
||||
"foo";
|
||||
"use strict";
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1347: 'use strict' directive cannot be used with non-simple parameter list.
|
||||
!!! related TS1348 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:39:23: Non-simple parameter declared here.
|
||||
!!! related TS6204 tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts:39:31: and here.
|
||||
}
|
||||
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
const c = 1;
|
||||
"use strict";
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
//// [functionWithUseStrictAndSimpleParameterList_es2016.ts]
|
||||
function a(a = 10) {
|
||||
"use strict";
|
||||
}
|
||||
|
||||
export var foo = 10;
|
||||
function b(a = 10) {
|
||||
}
|
||||
|
||||
function container() {
|
||||
"use strict";
|
||||
function f(a = 10) {
|
||||
}
|
||||
}
|
||||
|
||||
function rest(...args: any[]) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function rest1(a = 1, ...args) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function paramDefault(param = 1) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function objectBindingPattern({foo}: any) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function arrayBindingPattern([foo]: any[]) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
const c = 1;
|
||||
"use strict";
|
||||
}
|
||||
|
||||
|
||||
//// [functionWithUseStrictAndSimpleParameterList_es2016.js]
|
||||
function a(a = 10) {
|
||||
"use strict";
|
||||
}
|
||||
export var foo = 10;
|
||||
function b(a = 10) {
|
||||
}
|
||||
function container() {
|
||||
"use strict";
|
||||
function f(a = 10) {
|
||||
}
|
||||
}
|
||||
function rest(...args) {
|
||||
'use strict';
|
||||
}
|
||||
function rest1(a = 1, ...args) {
|
||||
'use strict';
|
||||
}
|
||||
function paramDefault(param = 1) {
|
||||
'use strict';
|
||||
}
|
||||
function objectBindingPattern({ foo }) {
|
||||
'use strict';
|
||||
}
|
||||
function arrayBindingPattern([foo]) {
|
||||
'use strict';
|
||||
}
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
"use strict";
|
||||
}
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
"use strict";
|
||||
}
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
const c = 1;
|
||||
"use strict";
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
=== tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts ===
|
||||
function a(a = 10) {
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 0, 11))
|
||||
|
||||
"use strict";
|
||||
}
|
||||
|
||||
export var foo = 10;
|
||||
>foo : Symbol(foo, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 4, 10))
|
||||
|
||||
function b(a = 10) {
|
||||
>b : Symbol(b, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 4, 20))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 5, 11))
|
||||
}
|
||||
|
||||
function container() {
|
||||
>container : Symbol(container, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 6, 1))
|
||||
|
||||
"use strict";
|
||||
function f(a = 10) {
|
||||
>f : Symbol(f, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 9, 17))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 10, 15))
|
||||
}
|
||||
}
|
||||
|
||||
function rest(...args: any[]) {
|
||||
>rest : Symbol(rest, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 12, 1))
|
||||
>args : Symbol(args, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 14, 14))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function rest1(a = 1, ...args) {
|
||||
>rest1 : Symbol(rest1, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 16, 1))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 18, 15))
|
||||
>args : Symbol(args, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 18, 21))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function paramDefault(param = 1) {
|
||||
>paramDefault : Symbol(paramDefault, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 20, 1))
|
||||
>param : Symbol(param, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 22, 22))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function objectBindingPattern({foo}: any) {
|
||||
>objectBindingPattern : Symbol(objectBindingPattern, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 24, 1))
|
||||
>foo : Symbol(foo, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 26, 31))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function arrayBindingPattern([foo]: any[]) {
|
||||
>arrayBindingPattern : Symbol(arrayBindingPattern, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 28, 1))
|
||||
>foo : Symbol(foo, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 30, 30))
|
||||
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
>manyParameter : Symbol(manyParameter, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 32, 1))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 34, 23))
|
||||
>b : Symbol(b, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 34, 30))
|
||||
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
>manyPrologue : Symbol(manyPrologue, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 36, 1))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 38, 22))
|
||||
>b : Symbol(b, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 38, 29))
|
||||
|
||||
"foo";
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
>invalidPrologue : Symbol(invalidPrologue, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 41, 1))
|
||||
>a : Symbol(a, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 43, 25))
|
||||
>b : Symbol(b, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 43, 32))
|
||||
|
||||
"foo";
|
||||
const c = 1;
|
||||
>c : Symbol(c, Decl(functionWithUseStrictAndSimpleParameterList_es2016.ts, 45, 9))
|
||||
|
||||
"use strict";
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
=== tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList_es2016.ts ===
|
||||
function a(a = 10) {
|
||||
>a : (a?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
}
|
||||
|
||||
export var foo = 10;
|
||||
>foo : number
|
||||
>10 : 10
|
||||
|
||||
function b(a = 10) {
|
||||
>b : (a?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
}
|
||||
|
||||
function container() {
|
||||
>container : () => void
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
|
||||
function f(a = 10) {
|
||||
>f : (a?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
}
|
||||
}
|
||||
|
||||
function rest(...args: any[]) {
|
||||
>rest : (...args: any[]) => void
|
||||
>args : any[]
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function rest1(a = 1, ...args) {
|
||||
>rest1 : (a?: number, ...args: any[]) => void
|
||||
>a : number
|
||||
>1 : 1
|
||||
>args : any[]
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function paramDefault(param = 1) {
|
||||
>paramDefault : (param?: number) => void
|
||||
>param : number
|
||||
>1 : 1
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function objectBindingPattern({foo}: any) {
|
||||
>objectBindingPattern : ({ foo }: any) => void
|
||||
>foo : any
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function arrayBindingPattern([foo]: any[]) {
|
||||
>arrayBindingPattern : ([foo]: any[]) => void
|
||||
>foo : any
|
||||
|
||||
'use strict';
|
||||
>'use strict' : "use strict"
|
||||
}
|
||||
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
>manyParameter : (a?: number, b?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
>b : number
|
||||
>20 : 20
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
}
|
||||
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
>manyPrologue : (a?: number, b?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
>b : number
|
||||
>20 : 20
|
||||
|
||||
"foo";
|
||||
>"foo" : "foo"
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
}
|
||||
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
>invalidPrologue : (a?: number, b?: number) => void
|
||||
>a : number
|
||||
>10 : 10
|
||||
>b : number
|
||||
>20 : 20
|
||||
|
||||
"foo";
|
||||
>"foo" : "foo"
|
||||
|
||||
const c = 1;
|
||||
>c : 1
|
||||
>1 : 1
|
||||
|
||||
"use strict";
|
||||
>"use strict" : "use strict"
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
function a(a = 10) {
|
||||
"use strict";
|
||||
}
|
||||
|
||||
export var foo = 10;
|
||||
function b(a = 10) {
|
||||
}
|
||||
|
||||
function container() {
|
||||
"use strict";
|
||||
function f(a = 10) {
|
||||
}
|
||||
}
|
||||
|
||||
function rest(...args: any[]) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function rest1(a = 1, ...args) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function paramDefault(param = 1) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function objectBindingPattern({foo}: any) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function arrayBindingPattern([foo]: any[]) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
const c = 1;
|
||||
"use strict";
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
// @target: es2016
|
||||
|
||||
function a(a = 10) {
|
||||
"use strict";
|
||||
}
|
||||
|
||||
export var foo = 10;
|
||||
function b(a = 10) {
|
||||
}
|
||||
|
||||
function container() {
|
||||
"use strict";
|
||||
function f(a = 10) {
|
||||
}
|
||||
}
|
||||
|
||||
function rest(...args: any[]) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function rest1(a = 1, ...args) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function paramDefault(param = 1) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function objectBindingPattern({foo}: any) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function arrayBindingPattern([foo]: any[]) {
|
||||
'use strict';
|
||||
}
|
||||
|
||||
function manyParameter(a = 10, b = 20) {
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function manyPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
"use strict";
|
||||
}
|
||||
|
||||
function invalidPrologue(a = 10, b = 20) {
|
||||
"foo";
|
||||
const c = 1;
|
||||
"use strict";
|
||||
}
|
Loading…
Reference in a new issue