Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid compiling the _typeof helper with itself (#11049)
* Avoid compiling the typeof helper with itself * Update fixtures
- Loading branch information
1 parent
d0518b7
commit 916429b
Showing
17 changed files
with
88 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/7030/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/babel-plugin-transform-classes/test/fixtures/regression/T7537/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/builtin-global/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; }; } else { _typeof = function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; }; } else { _typeof = function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
|
||
(typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object"; |
2 changes: 1 addition & 1 deletion
2
...ages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/default-export/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/babel-plugin-transform-typeof-symbol/test/fixtures/symbols/shadow/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/babel-plugin-transform-typeof-symbol/test/helper.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as babel from "@babel/core"; | ||
import resolvePath from "resolve"; | ||
import fs from "fs"; | ||
|
||
import transformTypeofSymbol from ".."; | ||
|
||
const resolve = path => | ||
new Promise((resolve, reject) => | ||
resolvePath(path, (err, path) => (err ? reject(err) : resolve(path))), | ||
); | ||
const readFile = path => | ||
new Promise((resolve, reject) => | ||
fs.readFile(path, "utf8", (err, contents) => { | ||
if (err) reject(err); | ||
else resolve(contents); | ||
}), | ||
); | ||
|
||
describe("@babel/plugin-transform-typeof-symbol", () => { | ||
test.each` | ||
runtime | type | ||
${"@babel/runtime"} | ${"esm"} | ||
${"@babel/runtime"} | ${"cjs"} | ||
${"@babel/runtime-corejs2"} | ${"esm"} | ||
${"@babel/runtime-corejs2"} | ${"cjs"} | ||
${"@babel/runtime-corejs3"} | ${"esm"} | ||
${"@babel/runtime-corejs3"} | ${"cjs"} | ||
`( | ||
"shouldn't transpile the $type $runtime helper", | ||
async ({ type, runtime }) => { | ||
const path = await resolve( | ||
`${runtime}/helpers${type === "esm" ? "/esm/" : "/"}typeof`, | ||
); | ||
const src = await readFile(path); | ||
|
||
const ast = babel.parseSync(src, { | ||
configFile: false, | ||
sourceType: type === "esm" ? "module" : "script", | ||
}); | ||
|
||
const withPlugin = babel.transformFromAstSync(ast, src, { | ||
configFile: false, | ||
plugins: [transformTypeofSymbol], | ||
}); | ||
const withoutPlugin = babel.transformFromAstSync(ast, src, { | ||
configFile: false, | ||
}); | ||
|
||
expect(withPlugin.code).toBe(withoutPlugin.code); | ||
}, | ||
); | ||
}); |
2 changes: 1 addition & 1 deletion
2
...preset-env/test/fixtures/dynamic-import/auto-esm-unsupported-import-unsupported/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/babel-preset-env/test/fixtures/dynamic-import/modules-amd/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/babel-preset-env/test/fixtures/dynamic-import/modules-cjs/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/babel-preset-env/test/fixtures/plugins-integration/issue-7527/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...babel-preset-env/test/fixtures/preset-options/loose-with-typeof-symbol-includes/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"use strict"; | ||
|
||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
|
||
_typeof(Symbol()); |