Skip to content

Commit

Permalink
Fix createSuper in Babel <7.5.5 (#11341)
Browse files Browse the repository at this point in the history
* Fix createSuper in Babel <7.5.5

In Babel <7.5.5, addHelper only throws when called for the first time.
This was fixed by #10208, but since we are already adding
a workaround for <7.9.0, we may as well fix <7.5.5

* Use 7.0.0 in "babel-old-version" test
  • Loading branch information
nicolo-ribaudo committed Apr 2, 2020
1 parent c3042cf commit 2c31587
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Expand Up @@ -3,18 +3,18 @@ import { template, types as t } from "@babel/core";
const helperIDs = new WeakMap();

export default function addCreateSuperHelper(file) {
try {
return file.addHelper("createSuper");
} catch {
// Babel <7.9.0 doesn't support the helper.
}

if (helperIDs.has(file)) {
// TODO: Only use t.cloneNode in Babel 8
// t.cloneNode isn't supported in every version
return (t.cloneNode || t.clone)(helperIDs.get(file));
}

try {
return file.addHelper("createSuper");
} catch {
// Babel <7.9.0 doesn't support the helper.
}

const id = file.scope.generateUidIdentifier("createSuper");
helperIDs.set(file, id);

Expand Down
9 changes: 3 additions & 6 deletions scripts/integration-tests/e2e-babel-old-version.sh
Expand Up @@ -23,15 +23,12 @@ cd ../..
startLocalRegistry "$PWD"/scripts/integration-tests/verdaccio-config.yml
yarn upgrade --scope @babel

# We use @babel/core 7.5.5 instead of 7.0.0 because without babel/babel#10208
# our @babel/standalone build fails.

node -e "\
var pkg = require('./package.json');\
pkg.devDependencies['@babel/core'] = '7.5.5';\
pkg.devDependencies['@babel/core'] = '7.0.0';\
Object.assign(pkg.resolutions, {\
'@babel/core': '7.5.5',\
'@babel/helpers': '7.5.5',\
'@babel/core': '7.0.0',\
'@babel/helpers': '7.0.0',\
'@babel/traverse': '7.0.0'\
});\
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));\
Expand Down

0 comments on commit 2c31587

Please sign in to comment.