forked from babel/babel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
systemjs
re-traverses helpers (babel#16225)
Co-authored-by: Nicolò Ribaudo <hello@nicr.dev>
- Loading branch information
1 parent
0da0161
commit ce8590d
Showing
13 changed files
with
174 additions
and
14 deletions.
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