update substitution placeholder message in @babel/template (#7255)

This commit is contained in:
Owen Buckley 2018-01-30 11:54:31 -05:00 committed by Henry Zhu
parent 3316a554bf
commit 2185256589
2 changed files with 15 additions and 2 deletions

View File

@ -15,7 +15,14 @@ export default function populatePlaceholders(
if (
!Object.prototype.hasOwnProperty.call(replacements, placeholder.name)
) {
throw new Error(`No substitution given for "${placeholder.name}"`);
const placeholderName = placeholder.name;
throw new Error(
`Error: No substitution given for "${placeholderName}". If this is not meant to be a
placeholder you may want to consider passing one of the following options to babel-template:
- { placeholderPattern: false, placeholderWhitelist: new Set(['${placeholderName}'])}
- { placeholderPattern: /^${placeholderName}$/ }`,
);
}
});
Object.keys(replacements).forEach(key => {

View File

@ -133,7 +133,13 @@ describe("babel-template", function() {
ID;
ANOTHER_ID;
`)({ ID: t.identifier("someIdent") });
}).to.throw(Error, 'No substitution given for "ANOTHER_ID"');
}).to.throw(
Error,
`Error: No substitution given for "ANOTHER_ID". If this is not meant to be a
placeholder you may want to consider passing one of the following options to babel-template:
- { placeholderPattern: false, placeholderWhitelist: new Set(['ANOTHER_ID'])}
- { placeholderPattern: /^ANOTHER_ID$/ }`,
);
});
it("should return the AST directly when using .ast", () => {