Skip to content
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

Use the correct context when re-using a cached NodePath #12331

Merged
merged 2 commits into from Nov 10, 2020

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Nov 7, 2020

Q                       A
Fixed Issues? Fixes #12329
Patch: Bug Fix? Yes
Major: Breaking Change? ?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

When re-using a cached path, by default we didn't update the context/opts. This means that, if I traverse a node with { noScope: true } and then re-traverse it with { noScope: false }, the second one will still have noScope: true because it re-uses the cached path with the original context.

The error in #12329 happens because we introduced noScope: true in a traversal used by the SystemJS plugin in Program:enter, and that leaked in to the class properties plugin, causing constructor.scope to be undefined in the helper-class-features package.

This is technically a breaking change (we are changing the default value of a parameter in the public API), but I couldn't find anyone online using that parameter and I'm not sure why anyway would not wont it to use the correct context.

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: traverse i: regression labels Nov 7, 2020
@@ -6,7 +6,7 @@ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why the tmp var name is changing here.

@babel-bot
Copy link
Collaborator

babel-bot commented Nov 7, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/31959/

@@ -9,8 +11,6 @@ var _args = _interopRequireDefault(require("utils/url/args"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": 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); }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ironically, this test was about another context caching bug (#6057), but this change has nothing to do with that bug.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 7, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit e7ce1ba:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration
babel-repl-custom-plugin Issue #12329

@@ -43,6 +43,10 @@ node "$PWD"/scripts/integration-tests/utils/bump-babel-dependencies.js
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
"

# https://github.com/babel/babel/pull/12331 - This test is fixed in @babel/traverse 7.12.7,
# so it will fail with older versions. We can disable it.
(cd packages/babel-plugin-transform-modules-systemjs/test/fixtures/regression/; mv issue-12329 .issue-12329)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about supporting minBabelVersion in fixture runner 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if this problem comes up more than once 😛

@JLHwung JLHwung self-requested a review November 9, 2020 22:08
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context parameter was implemented in 4c0b859. I believe it is an unwanted side effect that by default NodePath#get does not reset correct context.

@nicolo-ribaudo nicolo-ribaudo merged commit 2984f0c into babel:main Nov 10, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the issue-12329 branch November 10, 2020 14:03
@salvoravida
Copy link

image

after this pr, my project crash ...

@salvoravida

This comment has been minimized.

@ycjcl868
Copy link

image

@nicolo-ribaudo
Copy link
Member Author

@ycjcl868 I'm not sure how it is related to this PR, could you open a new issue? 🙏

@ycjcl868
Copy link

ycjcl868 commented Nov 23, 2020

When I reset this line code, the build is passed.

I think this line code would make import() syntax convert into require() syntax before the other babel plugin.

@nicolo-ribaudo
Copy link
Member Author

Thanks, investigating.

@JLHwung
Copy link
Contributor

JLHwung commented Nov 23, 2020

@ycjcl868 It's after midnight in Hangzhou, have a good night. We are investigating, a patch will be released today.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 23, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: traverse PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7.12 BUG: Cannot read property 'hasOwnBinding' of null; class property; initializer; SystemJS
6 participants