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

Fix several edge cases with context expression state #8972

Merged
merged 3 commits into from Nov 7, 2018
Merged

Conversation

@danez
Copy link
Member

@danez danez commented Nov 5, 2018

Q                       A
Fixed Issues? Fixes #8891 Fixes #7993
Patch: Bug Fix? y
Major: Breaking Change? n
Minor: New Feature? n
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

I started fixing #8891 and ended in an endless loop of breaking things with the fixes and having to fix that.

I took a lot of fixes from acorn, and reported a bunch of issues to acorn too.

// because parseIdentifier will remove an item from the expression stack
// if function or class is parsed as identifier (in objects e.g.).
let meta = this.startNode();
this.next();

This comment has been minimized.

@nicolo-ribaudo

nicolo-ribaudo Nov 5, 2018
Member

Could you add a comment which explains that when this function is called we already know that there is a function token?

if (
(name === "class" || name === "function") &&
(this.state.lastTokEnd !== this.state.lastTokStart + 1 ||
this.input.charCodeAt(this.state.lastTokStart) !== 46)

This comment has been minimized.

@nicolo-ribaudo

nicolo-ribaudo Nov 5, 2018
Member

Could you use the constants from charcodes here?

if (lineBreak.test(this.input.slice(this.state.end))) {
if (
lineBreak.test(
this.input.slice(this.state.end, this.lookahead(true).start),

This comment has been minimized.

@nicolo-ribaudo

nicolo-ribaudo Nov 5, 2018
Member

Does this do a lookahead every time we find var foo? Is it possible to avoid it somehow? 😟

This comment has been minimized.

@danez

danez Nov 6, 2018
Author Member

I removed this and instead used the same fix that acorn did by calling readRegex() in parseExprAtom()

@@ -1359,6 +1379,14 @@ export default class Tokenizer extends LocationParser {
return !this.state.exprAllowed;
}

inGeneratorContext() {

This comment has been minimized.

@nicolo-ribaudo

nicolo-ribaudo Nov 5, 2018
Member

Doesn't this.state.inGenerator work instead of this function?

This comment has been minimized.

@danez

danez Nov 6, 2018
Author Member

Yes works. Acorn does have both things too, but with the difference that they also allow running the tokenizer without the parser, that's why they need both inGenerator and inGeneratorContext.

@nicolo-ribaudo nicolo-ribaudo dismissed their stale review Nov 5, 2018

I didnìt mean to approve 😅 Good work, though. I started fixing some context issues a while ago but gave up because I couldn't touch anything without breaking something.

@danez danez mentioned this pull request Nov 6, 2018
@danez danez force-pushed the fix-expression-state branch from d6cb7f5 to 7e21cfe Nov 6, 2018
@babel-bot
Copy link
Collaborator

@babel-bot babel-bot commented Nov 6, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9344/

@@ -2392,7 +2393,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
refNeedsArrowPos?: ?Pos,
): N.Expression {
let jsxError = null;
if (tt.jsxTagStart && this.match(tt.jsxTagStart)) {
if (
this.hasPlugin("jsx") &&

This comment has been minimized.

@danez

danez Nov 6, 2018
Author Member

I had to replace this, as tt.jsxTagStart is always set in our tests, even if jsx plugin not loaded. Yeahh monkeypatching :)

This comment has been minimized.

@nicolo-ribaudo

nicolo-ribaudo Nov 6, 2018
Member

Yeah, that are the most hard to debug test failures 🤦‍♂️

@danez danez merged commit 5d5cd86 into master Nov 7, 2018
5 checks passed
5 checks passed
@babel-bot
babel/repl REPL preview is available
Details
ci/circleci Your tests passed on CircleCI!
Details
@codecov
codecov/project 80.65% (target 80%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@danez danez deleted the fix-expression-state branch Nov 7, 2018
@lock lock bot added the outdated label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants