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
fix: systemjs
re-traverses helpers
#16225
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8e6308f
fix
liuxingbaoyu 37bebff
review
liuxingbaoyu 8fb57e3
update tests
liuxingbaoyu 5143912
avoid globalThis
liuxingbaoyu 7bb07d3
test
liuxingbaoyu 07b4e19
test
liuxingbaoyu 9cdf541
Run test in vm context
nicolo-ribaudo d999bff
Ensure that the test is testing the correct behavior
nicolo-ribaudo 80960da
`yarn dedupe`
nicolo-ribaudo a1765b2
Regenerate makefile for deps update
nicolo-ribaudo 73cdf21
fix node 6
liuxingbaoyu 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
Large diffs are not rendered by default.
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
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
39 changes: 39 additions & 0 deletions
39
...babel-plugin-transform-modules-systemjs/test/fixtures/preset-env/requeue-helpers/input.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,39 @@ | ||
// Ref: https://github.com/babel/babel/issues/16219 | ||
|
||
// delete global.Symbol doesn't work with jest in node 6 | ||
Object.defineProperty(global, "Symbol", { | ||
configurable: true, | ||
writable: true, | ||
value: undefined | ||
}); | ||
|
||
require("core-js/modules/es.symbol.js"); | ||
require("core-js/modules/es.symbol.to-primitive"); | ||
|
||
const symbol = Symbol("test"); | ||
|
||
// Use eval to not let Babel transform this `typeof` | ||
expect(eval('typeof symbol')).toBe("object"); | ||
expect(typeof symbol).toBe("symbol"); | ||
|
||
function objectWithPrimitive(prim) { | ||
return { [Symbol.toPrimitive]: () => prim } | ||
} | ||
|
||
expect(() => { | ||
class AxiosHeaders { | ||
[objectWithPrimitive(symbol)]() { | ||
return; | ||
} | ||
} | ||
}).not.toThrow() | ||
|
||
expect(() => { | ||
class AxiosHeaders { | ||
[objectWithPrimitive({})]() { | ||
return; | ||
} | ||
} | ||
}).toThrow() | ||
|
||
return "ok"; |
15 changes: 15 additions & 0 deletions
15
...l-plugin-transform-modules-systemjs/test/fixtures/preset-env/requeue-helpers/options.json
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,15 @@ | ||
{ | ||
"parserOpts": { | ||
"allowReturnOutsideFunction": true | ||
}, | ||
"presets": [ | ||
[ | ||
"env", | ||
{ | ||
"targets": ["chrome 22", "last 12 years"], | ||
"modules": "systemjs" | ||
} | ||
] | ||
], | ||
"externalHelpers": false | ||
} |
68 changes: 68 additions & 0 deletions
68
...abel-plugin-transform-modules-systemjs/test/fixtures/preset-env/requeue-helpers/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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
System.register([], function (_export, _context) { | ||
"use strict"; | ||
|
||
var symbol; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } | ||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } | ||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } | ||
function objectWithPrimitive(prim) { | ||
return _defineProperty({}, Symbol.toPrimitive, function () { | ||
return prim; | ||
}); | ||
} | ||
return { | ||
setters: [], | ||
execute: function execute() { | ||
// Ref: https://github.com/babel/babel/issues/16219 | ||
|
||
// delete global.Symbol doesn't work with jest in node 6 | ||
Object.defineProperty(global, "Symbol", { | ||
configurable: true, | ||
writable: true, | ||
value: undefined | ||
}); | ||
require("core-js/modules/es.symbol.js"); | ||
require("core-js/modules/es.symbol.to-primitive"); | ||
symbol = Symbol("test"); // Use eval to not let Babel transform this `typeof` | ||
expect(eval('typeof symbol')).toBe("object"); | ||
expect(_typeof(symbol)).toBe("symbol"); | ||
expect(function () { | ||
var AxiosHeaders = /*#__PURE__*/function (_objectWithPrimitive) { | ||
"use strict"; | ||
|
||
function AxiosHeaders() { | ||
_classCallCheck(this, AxiosHeaders); | ||
} | ||
_createClass(AxiosHeaders, [{ | ||
key: _objectWithPrimitive, | ||
value: function value() { | ||
return; | ||
} | ||
}]); | ||
return AxiosHeaders; | ||
}(objectWithPrimitive(symbol)); | ||
}).not.toThrow(); | ||
expect(function () { | ||
var AxiosHeaders = /*#__PURE__*/function (_objectWithPrimitive2) { | ||
"use strict"; | ||
|
||
function AxiosHeaders() { | ||
_classCallCheck(this, AxiosHeaders); | ||
} | ||
_createClass(AxiosHeaders, [{ | ||
key: _objectWithPrimitive2, | ||
value: function value() { | ||
return; | ||
} | ||
}]); | ||
return AxiosHeaders; | ||
}(objectWithPrimitive({})); | ||
}).toThrow(); | ||
return "ok"; | ||
} | ||
}; | ||
}); |
33 changes: 33 additions & 0 deletions
33
packages/babel-plugin-transform-modules-systemjs/test/index.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,3 +1,36 @@ | ||
import runner from "@babel/helper-plugin-test-runner"; | ||
import { readFileSync } from "fs"; | ||
import { commonJS } from "$repo-utils"; | ||
import path from "path"; | ||
import { | ||
runCodeInTestContext, | ||
createTestContext, | ||
} from "@babel/helper-transform-fixture-test-runner"; | ||
|
||
const { __dirname } = commonJS(import.meta.url); | ||
|
||
runner(import.meta.url); | ||
|
||
describe("systemjs exec", function () { | ||
// https://github.com/babel/babel/issues/16219 | ||
it("should requeue helpers", function () { | ||
const filename = path.join( | ||
__dirname, | ||
"fixtures/preset-env/requeue-helpers/output.js", | ||
); | ||
const content = readFileSync(filename, "utf8"); | ||
|
||
let res; | ||
|
||
const context = createTestContext(); | ||
context.System = { | ||
register: function (_, module) { | ||
res = module().execute(); | ||
}, | ||
}; | ||
|
||
runCodeInTestContext(content, { filename }, context); | ||
|
||
expect(res).toBe("ok"); | ||
}); | ||
}); |
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
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.
To be honest, I don't understand how jest affects our isolation environment in node 6.
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.
Jest does bad things to the global object to implement isolation-but-not-too-much, this workaround is good enough.