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

embedAst option to embed assertion's AST and tokens to make runtime side parser unnecessary #13

Merged
merged 18 commits into from
May 27, 2016

Conversation

twada
Copy link
Member

@twada twada commented Mar 9, 2016

This pull-request aims to introduce opt-in embedAstoption to embed assertion's AST and tokens to make runtime side parser unnecessary.

Context

The runtime side of power-assert (not a transpilation side) depends on ECMAScript parser (currently acorn) to parse canonical assertion expression at runtime. Browserify embeds the parser into built bundle for web browsers.

Problems

ECMAScript parser is huge. Therefore,

  • it slows require time down
  • power-assert built bundle for browsers is huge too

Bundled parser is an ECMA standard compliant one. Therefore,

  • Cannot handle dialects such as JSX, Flow, etc...
  • When JSX expression exists inside of assert(), parser causes parse error, power-assert runtime explodes immediately.

Solution

  • Embed assertion's AST, tokens and its visitor keys to output code, means that they are passed to runtime side.
  • Now runtime side doesn't have to parse canonical assertion expression since they already have AST, tokens and its visitor keys.

Advantages

  • Reduce runtime side dependencies and its bundle size. Make runtime loading much faster.
  • Can handle any dialects such as JSX, Flow, etc... anything we can parse could be visualized on the runtime side

When this pull-req lands, you can write JSX tags inside assertions.

assert(shallow(<ToDoItem item={item} />).find('.item-mark').text() === '✓');

Downside

  • Slows down transpilation time
  • Transpiled code gets bigger

TODO

  • rough initial design
  • JSX testcase
  • spike implementation
  • reorganize runtime side
  • maint other tests
  • benchmarking
  • brutal refactoring
  • a little optimization

This feature might be released with power-assert 2.0.0 (if there are some breaking changes) <- No. There is no breaking changes.

@twada twada changed the title [WIP][experimental] Big refactring: Embed assertion's AST and tokens to make runtime side parser unnecessary [WIP][experimental] Big refactoring: Embed assertion's AST and tokens to make runtime side parser unnecessary Mar 9, 2016
@twada twada changed the title [WIP][experimental] Big refactoring: Embed assertion's AST and tokens to make runtime side parser unnecessary [WIP][experimental] Embed assertion's AST and tokens to make runtime side parser unnecessary Mar 21, 2016
@twada
Copy link
Member Author

twada commented Apr 6, 2016

Reorganization of runtime side has done. Time to move forward.

@twada twada changed the title [WIP][experimental] Embed assertion's AST and tokens to make runtime side parser unnecessary embedAst flag to embed assertion's AST and tokens to make runtime side parser unnecessary May 21, 2016
@twada twada changed the title embedAst flag to embed assertion's AST and tokens to make runtime side parser unnecessary embedAst option to embed assertion's AST and tokens to make runtime side parser unnecessary May 21, 2016
@twada twada merged commit 7f7219b into master May 27, 2016
@twada twada deleted the embedded-ast branch May 27, 2016 12:10
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.

1 participant