-
Notifications
You must be signed in to change notification settings - Fork 734
Split "use strict" into separate transformer, fix bugs with prologues #2028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f0120de
fd47f6b
3aba34a
42131c9
0a4887d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package estransforms | ||
|
|
||
| import ( | ||
| "github.com/microsoft/typescript-go/internal/ast" | ||
| "github.com/microsoft/typescript-go/internal/core" | ||
| "github.com/microsoft/typescript-go/internal/transformers" | ||
| ) | ||
|
|
||
| func NewUseStrictTransformer(opts *transformers.TransformOptions) *transformers.Transformer { | ||
| tx := &useStrictTransformer{ | ||
| compilerOptions: opts.CompilerOptions, | ||
| getEmitModuleFormatOfFile: opts.GetEmitModuleFormatOfFile, | ||
| } | ||
| return tx.NewTransformer(tx.visit, opts.Context) | ||
| } | ||
|
|
||
| type useStrictTransformer struct { | ||
| transformers.Transformer | ||
| compilerOptions *core.CompilerOptions | ||
| getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind | ||
| } | ||
|
|
||
| func (tx *useStrictTransformer) visit(node *ast.Node) *ast.Node { | ||
| if node.Kind != ast.KindSourceFile { | ||
| return node | ||
| } | ||
| return tx.visitSourceFile(node.AsSourceFile()) | ||
| } | ||
|
|
||
| func (tx *useStrictTransformer) visitSourceFile(node *ast.SourceFile) *ast.Node { | ||
| if node.ScriptKind == core.ScriptKindJSON { | ||
| return node.AsNode() | ||
| } | ||
|
|
||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if tx.compilerOptions.GetEmitModuleKind() == core.ModuleKindPreserve { | ||
| return node.AsNode() | ||
| } | ||
|
|
||
| isExternalModule := ast.IsExternalModule(node) | ||
| format := tx.getEmitModuleFormatOfFile(node) | ||
|
|
||
| if isExternalModule && format >= core.ModuleKindES2015 { | ||
| return node.AsNode() | ||
| } | ||
|
|
||
| if isExternalModule || | ||
| tx.compilerOptions.AlwaysStrict.DefaultIfUnknown(tx.compilerOptions.Strict).IsTrue() { | ||
| statements := tx.Factory().EnsureUseStrict(node.Statements.Nodes) | ||
| statementList := tx.Factory().NewNodeList(statements) | ||
| statementList.Loc = node.Statements.Loc | ||
| return tx.Factory().UpdateSourceFile(node, statementList, node.EndOfFileToken).AsSourceFile().AsNode() | ||
| } | ||
|
|
||
| return node.AsNode() | ||
| } | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,4 +19,5 @@ wat as Wat<string>; | |
|
|
||
|
|
||
| //// [aliasInstantiationExpressionGenericIntersectionNoCrash2.js] | ||
| "use strict"; | ||
| wat; | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ function f() { | |
| } | ||
|
|
||
| //// [alwaysStrict.js] | ||
| "use strict"; | ||
| function f() { | ||
| var arguments = []; | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ function f() { | |
| } | ||
|
|
||
| //// [alwaysStrictES6.js] | ||
| "use strict"; | ||
| function f() { | ||
| var arguments = []; | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ module M { | |
| } | ||
|
|
||
| //// [alwaysStrictModule.js] | ||
| "use strict"; | ||
| var M; | ||
| (function (M) { | ||
| function f() { | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.