Skip to content

Commit 2185256

Browse files
thescientist13hzoo
authored andcommitted
update substitution placeholder message in @babel/template (babel#7255)
1 parent 3316a55 commit 2185256

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/babel-template/src/populate.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ export default function populatePlaceholders(
1515
if (
1616
!Object.prototype.hasOwnProperty.call(replacements, placeholder.name)
1717
) {
18-
throw new Error(`No substitution given for "${placeholder.name}"`);
18+
const placeholderName = placeholder.name;
19+
20+
throw new Error(
21+
`Error: No substitution given for "${placeholderName}". If this is not meant to be a
22+
placeholder you may want to consider passing one of the following options to babel-template:
23+
- { placeholderPattern: false, placeholderWhitelist: new Set(['${placeholderName}'])}
24+
- { placeholderPattern: /^${placeholderName}$/ }`,
25+
);
1926
}
2027
});
2128
Object.keys(replacements).forEach(key => {

packages/babel-template/test/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ describe("babel-template", function() {
133133
ID;
134134
ANOTHER_ID;
135135
`)({ ID: t.identifier("someIdent") });
136-
}).to.throw(Error, 'No substitution given for "ANOTHER_ID"');
136+
}).to.throw(
137+
Error,
138+
`Error: No substitution given for "ANOTHER_ID". If this is not meant to be a
139+
placeholder you may want to consider passing one of the following options to babel-template:
140+
- { placeholderPattern: false, placeholderWhitelist: new Set(['ANOTHER_ID'])}
141+
- { placeholderPattern: /^ANOTHER_ID$/ }`,
142+
);
137143
});
138144

139145
it("should return the AST directly when using .ast", () => {

0 commit comments

Comments
 (0)