Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always throw when add missing helpers #10208

Merged
merged 1 commit into from Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/babel-core/src/transformation/file/file.js
Expand Up @@ -203,6 +203,9 @@ export default class File {
if (res) return res;
}

// make sure that the helper exists
helpers.ensure(name);

const uid = (this.declarations[name] = this.scope.generateUidIdentifier(
name,
));
Expand Down
24 changes: 24 additions & 0 deletions packages/babel-core/test/api.js
Expand Up @@ -788,4 +788,28 @@ describe("api", function() {
);
});
});

describe("missing helpers", function() {
it("should always throw", function() {
expect(() =>
babel.transformSync(``, {
configFile: false,
plugins: [
function() {
return {
visitor: {
Program(path) {
try {
path.pushContainer("body", this.addHelper("fooBar"));
} catch {}
path.pushContainer("body", this.addHelper("fooBar"));
},
},
};
},
],
}),
).toThrow();
});
});
});
4 changes: 4 additions & 0 deletions packages/babel-helpers/src/index.js
Expand Up @@ -280,6 +280,10 @@ export function getDependencies(name: string): $ReadOnlyArray<string> {
return Array.from(loadHelper(name).dependencies.values());
}

export function ensure(name: string) {
loadHelper(name);
}

export const list = Object.keys(helpers)
.map(name => name.replace(/^_/, ""))
.filter(name => name !== "__esModule");
Expand Down