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
Avoid compiling the _typeof helper with itself #11049
Merged
nicolo-ribaudo
merged 2 commits into
babel:master
from
nicolo-ribaudo:typeof-circular-fix
Jan 27, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be refactored using
util.promisify
Example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not supported by Node 6.
When we'll drop it, we'll directly use
fs.promises
.