Merge pull request #7925 from Microsoft/correctStrictPrologueCheckToTransforms

Correct strict prologue check to transforms
This commit is contained in:
Daniel Rosenwasser 2016-04-07 12:37:42 -07:00
commit 4446727fa6
6 changed files with 41 additions and 2 deletions

View File

@ -7636,7 +7636,7 @@ const _super = (function (geti, seti) {
}
function isUseStrictPrologue(node: ExpressionStatement): boolean {
return !!(node.expression as StringLiteral).text.match(/use strict/);
return (node.expression as StringLiteral).text === "use strict";
}
function ensureUseStrictPrologue(startWithNewLine: boolean, writeUseStrict: boolean) {

View File

@ -1202,7 +1202,7 @@ namespace ts {
// Utilities
function isUseStrictPrologue(node: ExpressionStatement): boolean {
return !!(node.expression as StringLiteral).text.match(/use strict/);
return (node.expression as StringLiteral).text === "use strict";
}
export function addPrologueDirectives(target: Statement[], source: Statement[], ensureUseStrict?: boolean): number {

View File

@ -0,0 +1,14 @@
//// [useStrictLikePrologueString01.ts]
"hey!"
" use strict "
export function f() {
}
//// [useStrictLikePrologueString01.js]
"hey!";
" use strict ";
"use strict";
function f() {
}
exports.f = f;

View File

@ -0,0 +1,7 @@
=== tests/cases/compiler/useStrictLikePrologueString01.ts ===
"hey!"
" use strict "
export function f() {
>f : Symbol(f, Decl(useStrictLikePrologueString01.ts, 2, 14))
}

View File

@ -0,0 +1,11 @@
=== tests/cases/compiler/useStrictLikePrologueString01.ts ===
"hey!"
>"hey!" : string
" use strict "
>" use strict " : string
export function f() {
>f : () => void
}

View File

@ -0,0 +1,7 @@
//@target: commonjs
//@target: es5
"hey!"
" use strict "
export function f() {
}