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

Lazy evaluation for cooked template string #1103

Merged
merged 3 commits into from
Mar 26, 2021

Conversation

jevancc
Copy link
Contributor

@jevancc jevancc commented Jan 27, 2021

This Pull Request makes the evaluation of cooked template strings lazily, which improves the performance in some cases and fixes invalid escapes in raw template strings. The following sample is now supported

function hello(s) { 
    return s.raw; 
}

hello`\u\x`;

It changes the following:

  • Add struct TemplateString and update template related keywords
  • Update tests
  • Fix bug: `use strict`; can not be used to invoke strict mode

@codecov
Copy link

codecov bot commented Jan 27, 2021

Codecov Report

Merging #1103 (2c2ab77) into master (038acb4) will increase coverage by 0.02%.
The diff coverage is 71.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1103      +/-   ##
==========================================
+ Coverage   58.81%   58.83%   +0.02%     
==========================================
  Files         176      176              
  Lines       12467    12468       +1     
==========================================
+ Hits         7332     7336       +4     
+ Misses       5135     5132       -3     
Impacted Files Coverage Δ
boa/src/syntax/parser/function/mod.rs 65.15% <0.00%> (+1.91%) ⬆️
boa/src/syntax/parser/expression/primary/mod.rs 69.84% <42.85%> (-3.05%) ⬇️
boa/src/syntax/lexer/token.rs 51.61% <66.66%> (-1.52%) ⬇️
boa/src/syntax/ast/node/template/mod.rs 55.00% <75.00%> (-0.18%) ⬇️
boa/src/syntax/lexer/template.rs 62.74% <75.00%> (+4.41%) ⬆️
...yntax/parser/expression/left_hand_side/template.rs 71.42% <83.33%> (ø)
...c/syntax/parser/expression/primary/template/mod.rs 79.31% <100.00%> (+8.34%) ⬆️
boa/src/syntax/parser/mod.rs 53.84% <100.00%> (+0.27%) ⬆️

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 038acb4...2c2ab77. Read the comment docs.

Fix octal escape in string literal


Add tests


Fix zero escape


Fix zero escape lookahead


Rename variables


Rename helper functions


Refactor match arms


Fix escape line terminator sequence


Fix single character escape


Fix line terminator and escape followed by unicode char


Add NonOctalDecimalEscapeSequence


Fix comment


Refactor


Modify error message


Add tests


Rename tests


Add test for error


Add comments for unsafe bytes to str


Update boa/src/syntax/lexer/string.rs

Co-authored-by: tofpie <75836434+tofpie@users.noreply.github.com>
Minor refactor


Remove unsafe bytes to str


Fix panic when reading invalid utf-8 chars


Refactor string literal


Support invalid utf-8 chars in string literal input


Add cook function for template literal


Fix line continuation bug


Add methods for utf16 buffer trait


Add trait comments


Add error message for template literal


Add and fix comments


Hide unused exported function and modify tests


Fix bug


Lazy evaluate cooked template string


Fix clippy


Fix test262 stack overflow issue


Fix invalid setting strict mode with template literal


Remove unnecessary cache


Remove
@jevancc jevancc force-pushed the lazy_cooked_template_str branch from b6f270d to 2c2ab77 Compare February 1, 2021 18:37
@jevancc jevancc marked this pull request as ready for review February 1, 2021 19:17
@RageKnify RageKnify added the parser Issues surrounding the parser label Feb 3, 2021
@RageKnify RageKnify requested review from tofpie, Lan2u and Razican February 3, 2021 15:04
@RageKnify RageKnify added this to the v0.12.0 milestone Feb 3, 2021
Copy link
Contributor

@tofpie tofpie left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks!

Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

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

Looks good to me! :)

@RageKnify RageKnify merged commit 6333daa into boa-dev:master Mar 26, 2021
Razican pushed a commit that referenced this pull request May 22, 2021
* Lazy evaluate cooked template string

Fix octal escape in string literal


Add tests


Fix zero escape


Fix zero escape lookahead


Rename variables


Rename helper functions


Refactor match arms


Fix escape line terminator sequence


Fix single character escape


Fix line terminator and escape followed by unicode char


Add NonOctalDecimalEscapeSequence


Fix comment


Refactor


Modify error message


Add tests


Rename tests


Add test for error


Add comments for unsafe bytes to str


Update boa/src/syntax/lexer/string.rs

Co-authored-by: tofpie <75836434+tofpie@users.noreply.github.com>
Minor refactor


Remove unsafe bytes to str


Fix panic when reading invalid utf-8 chars


Refactor string literal


Support invalid utf-8 chars in string literal input


Add cook function for template literal


Fix line continuation bug


Add methods for utf16 buffer trait


Add trait comments


Add error message for template literal


Add and fix comments


Hide unused exported function and modify tests


Fix bug


Lazy evaluate cooked template string


Fix clippy


Fix test262 stack overflow issue


Fix invalid setting strict mode with template literal


Remove unnecessary cache


Remove

* Add comments

* Minor update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Issues surrounding the parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants