Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat: unknown bindings and unknown patterns #1804

Merged
merged 14 commits into from
Nov 23, 2021

Conversation

ematipico
Copy link
Contributor

@ematipico ematipico commented Nov 19, 2021

Summary

This PR adds more test cases and adds the correct unknown nodes inside existing test cases:

  • created new test cases to cover existing errors
  • eval, argments and yield will emit JS_UNKNOWN_BINDING
  • when parsing a pattern, we decide the unknown node based on the state of the parser
  • an incorrect usage of let will emit a JS_UNKNOWN_BINDING
  • an incorrect object pattern can generate a JS_UNKNOWN_PATTERN
     let { 5 } = foo;
  • an incorrect parameters list will generate a JS_UNKNOWN_PATTERN
     function foo(true) {}
  • incorrect functions will generate JS_UNKNOWN_BINDING
     function {}
       JS_PARAMETER_LIST@23..38
         LIST@23..37
           JS_UNKNOWN_BINDING@23..24
             L_CURLY@23..24 "{"
           JS_UNKNOWN_BINDING@24..25
             R_CURLY@24..25 "}"
           WHITESPACE@25..26 "\n"
           ERROR@26..34
             FUNCTION_KW@26..34 "function"
           WHITESPACE@34..35 " "
           JS_UNKNOWN_BINDING@35..36
             STAR@35..36 "*"
           ERROR@36..37
             L_PAREN@36..37 "("
         R_PAREN@37..38 ")"
    
  • updated the test suite with all the correct tests, extracted directly from the source code (comments)

Please refers to the new tests in the PR for more details. Make sure to search for JS_UNKNOWN_BINDING and JS_UNKNOWN_PATTERN.

Test Plan

cargo lint
cargo test
cargo format

@cloudflare-pages
Copy link

cloudflare-pages bot commented Nov 19, 2021

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 053b5fc
Status:⚡️  Build in progress...

View logs

@github-actions
Copy link

github-actions bot commented Nov 19, 2021

Test262 comparison coverage results on ubuntu-latest

Test result main count This PR count Difference
Total 17608 17608 0
Passed 16787 16771 ❌ ⏬ -16
Failed 820 836 ❌ ⏫ +16
Panics 1 1 0
Coverage 95.34% 95.25% -0.09%

@github-actions
Copy link

github-actions bot commented Nov 19, 2021

Test262 comparison coverage results on windows-latest

Test result main count This PR count Difference
Total 17608 17608 0
Passed 16787 16771 ❌ ⏬ -16
Failed 820 836 ❌ ⏫ +16
Panics 1 1 0
Coverage 95.34% 95.25% -0.09%
Failed tests (16):
xtask/src/coverage/test262/test\language\expressions\async-arrow-function\early-errors-arrow-body-contains-super-call.js
xtask/src/coverage/test262/test\language\expressions\async-arrow-function\early-errors-arrow-formals-contains-super-call.js
xtask/src/coverage/test262/test\language\expressions\async-function\early-errors-expression-body-contains-super-call.js
xtask/src/coverage/test262/test\language\expressions\async-function\early-errors-expression-formals-contains-super-call.js
xtask/src/coverage/test262/test\language\expressions\function\early-body-super-call.js
xtask/src/coverage/test262/test\language\expressions\function\early-params-super-call.js
xtask/src/coverage/test262/test\language\expressions\object\method-definition\early-errors-object-method-body-contains-super-call.js
xtask/src/coverage/test262/test\language\expressions\object\method-definition\early-errors-object-method-formals-contains-super-call.js
xtask/src/coverage/test262/test\language\expressions\object\method-definition\name-super-call-body.js
xtask/src/coverage/test262/test\language\expressions\object\method-definition\name-super-call-param.js
xtask/src/coverage/test262/test\language\statements\async-function\early-errors-declaration-body-contains-super-call.js
xtask/src/coverage/test262/test\language\statements\async-function\early-errors-declaration-formals-contains-super-call.js
xtask/src/coverage/test262/test\language\statements\class\definition\early-errors-class-method-body-contains-super-call.js
xtask/src/coverage/test262/test\language\statements\class\definition\early-errors-class-method-formals-contains-super-call.js
xtask/src/coverage/test262/test\language\statements\function\early-body-super-call.js
xtask/src/coverage/test262/test\language\statements\function\early-params-super-call.js

@ematipico ematipico changed the title feat: unknown bindings feat: unknown bindings and unknown patterns Nov 19, 2021
@ematipico ematipico marked this pull request as ready for review November 19, 2021 17:25
@yassere
Copy link
Contributor

yassere commented Nov 19, 2021

Were those new tests added manually into the /inline directory? I think those tests are intended to be extracted.

@ematipico
Copy link
Contributor Author

ematipico commented Nov 19, 2021

Were those new tests added manually into the /inline directory? I think those tests are intended to be extracted.

What do you mean by "extracted"?

Yes, I created manually the tests. Myself and Micha have been adding new tests in the /inline folder every time we change things in the parser, and it worked as intended - they are like snapshot tests.

@yassere
Copy link
Contributor

yassere commented Nov 19, 2021

The tests themselves would work as intended, but I think the idea is that you add the test cases "inline" to comments right next to the parser code they're testing and then the codegen extracts those comments into the inline directory.

So for example, these ok tests come from here and these err tests come from here.

@ematipico
Copy link
Contributor Author

ematipico commented Nov 19, 2021

Damn! I wished there was some documentation somewhere! If there was, I couldn't find it anywhere!

Thank you for letting me know, I will change that right away!

@ematipico
Copy link
Contributor Author

@MichaReiser I restored your tests by adding the new cases as commented code.

@ematipico ematipico force-pushed the fature/unknown-binding-nodes-2 branch from ce04d04 to 33fa14f Compare November 19, 2021 20:08
@MichaReiser
Copy link
Contributor

@MichaReiser I restored your tests by adding the new cases as commented code.

Thanks ema. How can I generate the inline tests? Is it a macro?

@ematipico
Copy link
Contributor Author

@MichaReiser I restored your tests by adding the new cases as commented code.

Thanks ema. How can I generate the inline tests? Is it a macro?

It's an xtask: cargo xtask codegen.

This will generate the JS files out of the comments.

Then we run the command to update the .rast files.

I guess we should start documenting all these findings

@ematipico ematipico force-pushed the feature/unknown-nodes-errors branch 2 times, most recently from 24629d5 to da8e59a Compare November 22, 2021 12:24
Copy link
Contributor

@yassere yassere left a comment

Choose a reason for hiding this comment

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

This looks good to me, but I haven't personally worked much with the internals of this part of the parser.

crates/rslint_parser/src/syntax/object.rs Outdated Show resolved Hide resolved
crates/rslint_parser/src/syntax/pat.rs Outdated Show resolved Hide resolved
crates/rslint_parser/src/syntax/object.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@MichaReiser MichaReiser 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 and thanks for recovering the tests.

The one thing I would change is to not distinguish between binding and pattern and only use JS_UNKNOWN_PATTERN because the current grammar doesn't make the distinction as well (that's what I've been working on when extracting assignment targets, and then later introduce bindings).

We may need to give this a second pass once we have refined our approach to error recovery.

crates/rslint_parser/src/syntax/pat.rs Outdated Show resolved Hide resolved
@ematipico ematipico merged commit 39523fe into feature/unknown-nodes-errors Nov 23, 2021
@ematipico ematipico deleted the fature/unknown-binding-nodes-2 branch November 23, 2021 12:16
p.error(err);
}

if p.at(T![await]) && p.state.in_async {
let err = p
.err_builder("Illegal use of `await` as an identifier in an async context")
.primary(p.cur_tok().range, "");

kind_to_change = JS_UNKNOWN_BINDING;
Copy link
Contributor

Choose a reason for hiding this comment

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

There were some more unknown bindings ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry @MichaReiser , I make this change later in another PR

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

Successfully merging this pull request may close these issues.

None yet

3 participants