Merge pull request #6280 from loganfsmyth/only-transform-modules
Only transform 'this'->'undefined' and inject 'use strict' if module statements are present
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
isModule,
|
||||
rewriteModuleStatementsAndPrepareHeader,
|
||||
isSideEffectImport,
|
||||
buildNamespaceInitStatements,
|
||||
@@ -11,6 +12,10 @@ export default function({ types: t }) {
|
||||
visitor: {
|
||||
Program: {
|
||||
exit(path, state) {
|
||||
// For now this requires unambiguous rather that just sourceType
|
||||
// because Babel currently parses all files as sourceType:module.
|
||||
if (!isModule(path, true /* requireUnambiguous */)) return;
|
||||
|
||||
const {
|
||||
loose,
|
||||
allowTopLevelThis,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
var foo = () => this;
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
var foo = () => void 0;
|
||||
@@ -0,0 +1 @@
|
||||
this.foo();
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
(void 0).foo();
|
||||
@@ -0,0 +1 @@
|
||||
var self = this;
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
var self = void 0;
|
||||
@@ -0,0 +1 @@
|
||||
this;
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
void 0;
|
||||
Reference in New Issue
Block a user