From 21852565896f005032716ff212a2422c31bdd509 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Tue, 30 Jan 2018 11:54:31 -0500 Subject: [PATCH] update substitution placeholder message in `@babel/template` (#7255) --- packages/babel-template/src/populate.js | 9 ++++++++- packages/babel-template/test/index.js | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/babel-template/src/populate.js b/packages/babel-template/src/populate.js index 90be31b8e4..d7c833635d 100644 --- a/packages/babel-template/src/populate.js +++ b/packages/babel-template/src/populate.js @@ -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 => { diff --git a/packages/babel-template/test/index.js b/packages/babel-template/test/index.js index 4c09bc28d6..e3794e2498 100644 --- a/packages/babel-template/test/index.js +++ b/packages/babel-template/test/index.js @@ -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", () => {