Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

The { after a function generic type annotation is a statement #578

Merged
merged 1 commit into from
Jun 15, 2017
Merged

The { after a function generic type annotation is a statement #578

merged 1 commit into from
Jun 15, 2017

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jun 14, 2017

Q A
Bug fix? yes
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? no
Tests added/pass? yes
Fixed tickets #36
License MIT

Usually after ">" there must be an expression, but not if ">" is the end of a generic type annotation. This wrong assumption caused the tokenizer to recognize the opening brace of a function (function(): a<b> {}) as the starting token of an expression, and thus not popping the function context.

The following would have been a better test case (since "regex" vs "/" is a clear symptom of "expression" or "not expression"), but I didn't know how to add a test which needed to be executed.

"use strict";

const assert = require("assert");
const babylon = require(".");

const parser = getParser({ plugins: ["flow", "jsx"] }, "(function a(): b<c> /d/);");

try {
  parser.parse();
  assert.fail();
} catch (e) {
  assert.equal(parser.state.type.label, "/"); // not "regexp"
}

This would have previously been interpreted as an expression,
because usually after ">" there can't be a statement.

Fixes #36
@codecov
Copy link

codecov bot commented Jun 14, 2017

Codecov Report

Merging #578 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #578      +/-   ##
==========================================
+ Coverage   98.14%   98.14%   +<.01%     
==========================================
  Files          22       22              
  Lines        3673     3674       +1     
  Branches     1024     1024              
==========================================
+ Hits         3605     3606       +1     
  Misses         25       25              
  Partials       43       43
Flag Coverage Δ
#babel 80.81% <100%> (ø) ⬆️
#babylon 96.81% <100%> (ø) ⬆️
Impacted Files Coverage Δ
src/plugins/flow.js 98.39% <100%> (ø) ⬆️

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 50ae16d...d3a1813. Read the comment docs.

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.

3 participants