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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰Expander: better support of backticks #26264

Merged
merged 4 commits into from
Jan 22, 2020
Merged

馃悰Expander: better support of backticks #26264

merged 4 commits into from
Jan 22, 2020

Conversation

calebcordry
Copy link
Member

Previously the parser ignoring feature only worked when an argument was completely wrapped in backticks eg FOO(abc, ` - `)

This allows backticks to be used anywhere inside of a macro to give raw input.

Follow up to #26247.

@zhouyx
Copy link
Contributor

zhouyx commented Jan 8, 2020

@micajuine-ho can you take a look. Thank you

@calebcordry
Copy link
Member Author

@micajuine-ho I saw you recently added ownership of url-replacements. Do you think we should add expander to wg-analytics as well?

@zhouyx zhouyx removed their request for review January 14, 2020 20:50
Copy link
Member Author

@calebcordry calebcordry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commenting to refresh owners bot.

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimming a string can be surprisingly expensive.

builder = '';
// Collect any chars that may exist before backticks, eg FOO(a`b`)
if (builder.trim().length) {
results.push(builder.trim());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Store the trimmed value, don't re-trim.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

);
builder = '';
// Collect any chars that may exist before backticks, eg FOO(a`b`)
if (builder.trim().length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: a length check is unnecessary, compare to an empty string or just let if (str) push(str);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// create a new array for the next argument, and reset our string
// builder.
// We push any string built so far, create a new array for the next
// argument, and reset our string builder.
if (builder.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you be checking trimmed length?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good catch. Done.

if (nextArg) {
results.push(nextArg);
if (builder.trim().length) {
results.push(builder.trim());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@calebcordry
Copy link
Member Author

Good to know about the trimming, thanks.

@calebcordry calebcordry merged commit 504d23e into ampproject:master Jan 22, 2020
@calebcordry calebcordry deleted the backticks branch January 22, 2020 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants