fix #478: add "--avoid-tdz" workaround for safari

This commit is contained in:
Evan Wallace
2020-10-20 18:03:30 -07:00
parent e51cb510b4
commit 09641c18f9
13 changed files with 127 additions and 8 deletions

View File

@@ -645,6 +645,49 @@ let transformTests = {
}
},
async avoidTDZ({ service }) {
for (const avoidTDZ of [false, true]) {
var { js } = await service.transform(`
class Foo {
// The above line will be transformed into "var". However, the
// symbol "Foo" must still be defined before the class body ends.
static foo = new Foo
}
if (!(Foo.foo instanceof Foo))
throw 'fail: avoidTDZ=${avoidTDZ}'
`, {
avoidTDZ,
})
new Function(js)()
}
},
async tsAvoidTDZ({ service }) {
for (const avoidTDZ of [false, true]) {
var { js } = await service.transform(`
class Bar {}
var oldFoo
function swap(target) {
oldFoo = target
return Bar
}
@swap
class Foo {
bar() { return new Foo }
static foo = new Foo
}
if (!(oldFoo.foo instanceof oldFoo))
throw 'fail: foo, avoidTDZ=${avoidTDZ}'
if (!(oldFoo.foo.bar() instanceof Bar))
throw 'fail: bar, avoidTDZ=${avoidTDZ}'
`, {
avoidTDZ,
loader: 'ts',
})
new Function(js)()
}
},
async cjs_require({ service }) {
const { js } = await service.transform(`const {foo} = require('path')`, {})
assert.strictEqual(js, `const {foo} = require("path");\n`)