| 1 |
import * as babel from "@babel/core"; |
| 2 |
import proposalClassStaticBlock from "../lib/index.js"; |
| 3 |
import proposalClassProperties from "@babel/plugin-proposal-class-properties"; |
| 4 |
|
| 5 |
describe("plugin ordering", () => { |
| 6 |
it("should work when @babel/plugin-proposal-class-static-block is after class features plugin", () => { |
| 7 |
const source = `class Foo { |
| 8 |
static { |
| 9 |
this.foo = Foo.bar; |
| 10 |
} |
| 11 |
static bar = 42; |
| 12 |
} |
| 13 |
`; |
| 14 |
expect( |
| 15 |
babel.transformSync(source, { |
| 16 |
filename: "example.js", |
| 17 |
highlightCode: false, |
| 18 |
configFile: false, |
| 19 |
babelrc: false, |
| 20 |
plugins: [proposalClassProperties, proposalClassStaticBlock], |
| 21 |
}).code, |
| 22 |
).toMatchInlineSnapshot(` |
| 23 |
"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; } |
| 24 |
function _toPropertyKey(arg) { var key = _toPrimitive(arg, \\"string\\"); return typeof key === \\"symbol\\" ? key : String(key); } |
| 25 |
function _toPrimitive(input, hint) { if (typeof input !== \\"object\\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \\"default\\"); if (typeof res !== \\"object\\") return res; throw new TypeError(\\"@@toPrimitive must return a primitive value.\\"); } return (hint === \\"string\\" ? String : Number)(input); } |
| 26 |
class Foo {} |
| 27 |
Foo.foo = Foo.bar; |
| 28 |
_defineProperty(Foo, \\"bar\\", 42);" |
| 29 |
`); |
| 30 |
}); |
| 31 |
}); |