Skip to content

Commit

Permalink
Ensure empty export-from specifier lists are transpiled.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Sep 17, 2018
1 parent 82f4a8d commit 669b7e5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
50 changes: 33 additions & 17 deletions src/visitor/import-export.js
Expand Up @@ -118,10 +118,11 @@ function init() {

const node = path.getValue()
const { specifiers } = node
const lastIndex = specifiers.length - 1
const { length } = specifiers
const lastIndex = length - 1
const specifierMap = createSpecifierMap(this, node)

let hoistedCode = specifiers.length
let hoistedCode = length
? (this.generateVarDeclarations ? "var " : "let ")
: ""

Expand Down Expand Up @@ -341,16 +342,35 @@ function init() {

const specifierName = source.value

addToDependencySpecifiers(this, specifierName)

const fromNames =
exportedFrom[specifierName] ||
(exportedFrom[specifierName] = [])

const lastIndex = specifiers.length - 1

let hoistedCode = pad(
original,
runtimeName + '.w("' + specifierName + '"',
node.start,
source.start
)

let i = -1
let setterArgsList = ""

addToDependencySpecifiers(this, specifierName)

for (const specifier of specifiers) {
const exportedName = specifier.exported.name
const localName = specifier.local.name

setterArgsList +=
'["' +
localName + '",null,' +
runtimeName + '.f("' + localName + '","' + exportedName +
'")]' +
(++i === lastIndex ? "" : ",")

exportedNames.push(exportedName)

if (exportedName === localName) {
Expand All @@ -359,21 +379,17 @@ function init() {
fromNames.push([exportedName, localName])
}

const hoistedCode = pad(
original,
runtimeName + '.w("' + specifierName + '"',
node.start,
source.start
) + pad(
original,
',[["' + localName + '",null,' + runtimeName + '.f("' + localName + '","' + exportedName + '")]]);',
source.end,
node.end
)

addToDependencySpecifiers(this, specifierName, localName)
hoistImports(this, node, hoistedCode)
}

hoistedCode += pad(
original,
",[" + setterArgsList + "]);",
source.end,
node.end
)

hoistImports(this, node, hoistedCode)
}
}

Expand Down
6 changes: 2 additions & 4 deletions test/test262.mjs
Expand Up @@ -7,7 +7,6 @@ import globby from "globby"
import path from "path"
import test262Parser from "test262-parser"

const isAppVeyor = Reflect.has(process.env, "APPVEYOR")
const isChakra = Reflect.has(process.versions, "chakracore")

const fixturePath = path.resolve("test262")
Expand Down Expand Up @@ -160,9 +159,8 @@ describe("test262 tests", function () {
} else {
assert.strictEqual(name, expected)
}
} else if (skipped &&
! isAppVeyor) {
assert.fail("Expected skipped test to fail")
} else if (skipped) {
this.skip()
}
})
})
Expand Down

0 comments on commit 669b7e5

Please sign in to comment.