-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
update substitution placeholder message in babel-template #7255
update substitution placeholder message in babel-template #7255
Conversation
thescientist13
commented
Jan 22, 2018
•
edited
Loading
edited
Q | A |
---|---|
Fixed Issues? | helps resolve #7035 |
Patch: Bug Fix? | Yes |
Major: Breaking Change? | No |
Minor: New Feature? | No |
Tests Added + Pass? | Yes |
Documentation PR | No |
Any Dependency Changes? | No |
License | MIT |
- Updated babel-template placeholder text for missing substitution per suggestion here
throw new Error(`No substitution given for "${placeholder.name}"`); | ||
throw new Error(`Error: No substitution given for "NODE_ENV". 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(['NODE']) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if
new Set(['NODE']
should be this ?
new Set(['NODE_ENV']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message should continue using placeholder.name
, don't think we want to say NODE_ENV
for every error :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@existentialism
Ah... of course!
Working on fixing the test, just getting a little hung up on formatting / linting for a multiline string in the test, example (I'm using Webstorm for IDE if it matters) $ TEST_ONLY=babel-template make test
./node_modules/.bin/eslint scripts packages codemods *.js --format=codeframe --rulesdir="./scripts/eslint_rules"
error: Delete `⏎········` (prettier/prettier) at packages/babel-template/src/populate.js:21:46:
19 | placeholder you may want to consider passing one of the following options to babel-template:
20 | - { placeholderPattern: false, placeholderWhitelist: new Set(['NODE']) }
> 21 | - { placeholderPattern: /^NODE$/ }`
| ^
22 | );
23 | }
24 | }); note: the test didn't fail locally for me running |
Try running |
@thescientist13 You need to modify the expected error message here https://github.com/babel/babel/blob/master/packages/babel-template/test/index.js#L130 |
thank you for that tip @maaz93 !! The console output showed
Now it's working! 🎉 |
thanks @abiduzz420, that's what I'm working on now 👍 |
think I got it now 🤞 |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6710/ |
throw new Error(`Error: No substitution given for "${ | ||
placeholder.name | ||
}". If this is not meant to be a | ||
placeholder you may want to consider passing one of the following options to babel-template: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this formatting was put in by prettier. maybe it expects {
to always be the start of an object and thus need a line break after?
let me know if this 🆗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Template literals, the ``, preserve spaces and new lines. You'll need to construct your string something like the way it's done here
`You appear to be using an async codegen plugin, ` + |
Otherwise, the error message will have unnecessary indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maaz93
It seems to keep complaining about that {
if (
!Object.prototype.hasOwnProperty.call(replacements, placeholder.name)
) {
throw new Error(
`Error: No substitution given for "${placeholder.name}". 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(['${placeholder.name}'])}` +
`- { placeholderPattern: /^${placeholder.name}$/ }`
);
}
error: Replace `··`Error:·No·substitution·given·for·"${placeholder.name` with ``Error:·No·substitution·given·for·"${⏎············placeholder.name⏎··········` (prettier/prettier) at packages/babel-template/src/populate.js:19:11:
17 | ) {
18 | throw new Error(
> 19 | `Error: No substitution given for "${placeholder.name}". If this is not meant ` +
| ^
20 | `to be a placeholder you may want to consider passing one of the following options to babel-template:` +
21 | `- { placeholderPattern: false, placeholderWhitelist: new Set(['${placeholder.name}'])}` +
22 | `- { placeholderPattern: /^${placeholder.name}$/ }`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. This seems a little tricky. I formatted it here to work fine:
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}$/ }`,
);
It was complaining about printWidth
and the {
placement. I've overcome the {
by not having a property access, rather storing it in placeholderName
. Also, I changed number of characters per line in one of the lines to meet the allowed printWidth
. Let me know if this works
It's generally recommended to run |
@maaz93 I have tried again with using `` for both still getting test failures on the expected vs actual
index.js
Locally with both implementations seemingly the same, I am seeing this test failure occuring 1) babel-template string-based should throw if placeholders are not given explicit values:
AssertionError: expected [Function] to throw error including 'Error: No substitution given for "ANOTHER_ID". If this is not meant to be a\n placeholder you may want to consider passing one of the following options to babel-template:\n - { placeholderPattern: false, placeholderWhitelist: new Set([\'ANOTHER_ID\']) }\n - { placeholderPattern: /^ANOTHER_ID$/ }' but got 'Error: No substitution given for "ANOTHER_ID". If this is not meant to be a placeholderyou may want to consider passing one of the following options to babel-template:- { placeholderPattern: false, placeholderWhitelist: new Set([\'ANOTHER_ID\'])}- { placeholderPattern: /^ANOTHER_ID$/ }'
+ expected - actual
-Error: No substitution given for "ANOTHER_ID". If this is not meant to be a placeholderyou may want to consider passing one of the following options to babel-template:- { placeholderPattern: false, placeholderWhitelist: new Set(['ANOTHER_ID'])}- { placeholderPattern: /^ANOTHER_ID$/ }
+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$/ } |
}).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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ES6 template literals take raw string, so if you have multi-line string, then it will automatically add new Line character there. However, when you use + (with strings), you are actually doing concatenation and not putting any new Line character there. I would suggest you to convert both of them into template literals, that would automatically add new line character in both. Hence resolving test!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @nveenjain
I forgot to include it in my comment, but locally both implementations are seemingly matching to me in terms of implementation, yet still getting a test failure on string construction. (I've since updated my comment to show everything)
I can push my changes if it helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is still constructed with multiline template string, you just have to adjust this one so it is constructed like the other one (the other one is correct)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Andarist
Do you mean in this PR? Yes I understand they are different and I know why they are incompatible, but if you see the updated link from my comment above, locally they seem identical to me. So still struggling with the difference between this
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}$/ }`,
);
and this
}).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$/ }`,
);
🤒
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
notice that in the source file (when throwing) the string is created (in the PR) with concatenation (+
) and in tests it's defined with multiline template literal
This:
const str1 = `first line` +
`second line`
and this:
const str2 = `first line
second line`
are not equivalents.
str1 === 'first linesecond line'
str2 === 'first line\n\t\t\t\t\t\t\t\t\t\t\t\tsecond line'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Andarist
Understood that is what is causing the failure in this PR specifically, but my comment was just trying to demonstrate what I was trying locally to fix the failure so as to avoid pushing intentionally failing commits.
I suppose that keeping my local work local is causing more confusion, so I will just push my latest changes.
Appreciate you helping out, sorry for any confusion, hopefully the issue I'm seeing will be better highlighted in a few moments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thescientist13 the difference is an extra space after "a" in your input vs output and from travis, as well as the subsequent whitespace:
'Error: No substitution given for "ANOTHER_ID". If this is not meant to be a\n placeholder you may want to consider passing one of the following options to babel-template:\n - { placeholderPattern: false, placeholderWhitelist: new Set([\'ANOTHER_ID\']) }\n - { placeholderPattern: /^ANOTHER_ID$/ }'
vs
'Error: No substitution given for "ANOTHER_ID". If this is not meant to be a \n placeholder you may want to consider passing one of the following options to babel-template:\n - { placeholderPattern: false, placeholderWhitelist: new Set([\'ANOTHER_ID\'])}\n - { placeholderPattern: /^ANOTHER_ID$/ }'`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @existentialism ! I think part of the issue is that what I see in CircleCI is different output than what I see locally. Will need to see if I need to align my local environment
- OSX: 10.13.2
- node: 6.9.1
- npm: 5.6.0
I think my next goal is to make my local try and match CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thescientist13 i pushed a change to your branch that should fix it, sorry for all the trouble digging into it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, thanks @existentialism !!
I'll certainly never underestimate a string again... 😌
const placeholderName = placeholder.name; | ||
|
||
throw new Error( | ||
`Error: No substitution given for "${placeholderName}". If this is not meant to be a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiline string like this will look weirdly in the console, personally I would prefer using regular concatenation for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point and appreciate your assistance / feedback.
String concatenation had been suggested before, but then I got too focused on the struggle with template string to step back and consider the alternatives and wanting to stick with the existing convention.
Lesson learned!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for sticking with this - we should use |