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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor directive parsing for code reuse #1242

Merged
merged 1 commit into from
Mar 15, 2018

Conversation

jacwright
Copy link
Contributor

This removes the copy-pasta for directive parsing and removes the need for special if-else cases for each directive. Future directives (if any) will benefit from this cleanup as well.

This removes the copy-pasta for directive parsing and removes the need for special if-else cases for each directive.
@codecov-io
Copy link

codecov-io commented Mar 15, 2018

Codecov Report

Merging #1242 into master will increase coverage by 0.17%.
The diff coverage is 97.43%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1242      +/-   ##
=========================================
+ Coverage   91.73%   91.9%   +0.17%     
=========================================
  Files         126     126              
  Lines        4571    4557      -14     
  Branches     1493    1486       -7     
=========================================
- Hits         4193    4188       -5     
+ Misses        157     153       -4     
+ Partials      221     216       -5
Impacted Files Coverage Δ
src/parse/state/tag.ts 96.12% <100%> (-0.28%) ⬇️
src/parse/read/directives.ts 87.09% <97.22%> (+13.65%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef1e2d0...6d4f8d8. Read the comment docs.

@@ -24,7 +83,7 @@ function readExpression(parser: Parser, start: number, quoteMark: string|null) {
} else {
str += char;
}
} else if (/\s/.test(char)) {
} else if (/[\s\r\n\/>]/.test(char)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

\s should match the same character group as [\s\r\n]...

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Special_characters_meaning_in_regular_expressions

Matches a single white space character, including space, tab, form feed, line feed and other Unicode spaces. Equivalent to [ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff].

For example, /\s\w*/ matches " bar" in "foo bar".

Matches a single white space character, including space, tab, form feed, line feed and other Unicode spaces. Equivalent to [ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff].For example, /\s\w*/ matches " bar" in "foo bar".

Copy link
Member

Choose a reason for hiding this comment

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

ah whoops, missed this review before i hit merge, will account for these comments in a follow-up. sorry!

@Rich-Harris Rich-Harris merged commit 6f866bb into sveltejs:master Mar 15, 2018
@@ -1,5 +1,5 @@
{
"message": "bound values should not be wrapped — use 'foo', not '{{foo}}'",
"message": "directive values should not be wrapped — use 'foo', not '{{foo}}'",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this tests the same thing. A directive is not the same thing as a bound value...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Directives are special attributes with a colon. Bindings happen to be one type of directive, but all directive expressions should not be wrapped. This is a more general message for any directives. I could change it to use the specific name of the directive. E.g. Binding values should not be wrapped and EventHandler values should not be wrapped. But since the error points to the code where the issue is, I don't feel this provides much.

Copy link
Member

Choose a reason for hiding this comment

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

Can see both sides of this, though I think it's probably ok to leave in —

on:click='{{set({foo: 'bar' })}}'

is just as incorrect as bind:value='{{foo}}', it's just less likely that someone would make that mistake.

@@ -1,5 +1,5 @@
{
"message": "Expected call expression",
"message": "Expected CallExpression",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is less expressive than using English.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, it is more literal. Are you thinking we should write a method to humanize the expression type in the errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants