jashkenas--coffeescript/lib/coffeescript/grammar.js

2172 lines
53 KiB
JavaScript
Raw Normal View History

// Generated by CoffeeScript 2.3.2
2010-07-25 07:15:12 +00:00
(function() {
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The CoffeeScript parser is generated by [Jison](https://github.com/zaach/jison)
// from this grammar file. Jison is a bottom-up parser generator, similar in
// style to [Bison](http://www.gnu.org/software/bison), implemented in JavaScript.
// It can recognize [LALR(1), LR(0), SLR(1), and LR(1)](https://en.wikipedia.org/wiki/LR_grammar)
// type grammars. To create the Jison parser, we list the pattern to match
// on the left-hand side, and the action to take (usually the creation of syntax
// tree nodes) on the right. As the parser runs, it
// shifts tokens from our token stream, from left to right, and
// [attempts to match](https://en.wikipedia.org/wiki/Bottom-up_parsing)
// the token sequence against the rules below. When a match can be made, it
// reduces into the [nonterminal](https://en.wikipedia.org/wiki/Terminal_and_nonterminal_symbols)
// (the enclosing name at the top), and we proceed from there.
// If you run the `cake build:parser` command, Jison constructs a parse table
// from our rules and saves it into `lib/parser.js`.
// The only dependency is on the **Jison.Parser**.
var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
[CS2] Destructuring (#4478) * Output simple array destructuring assignments to ES2015 * Output simple object destructured assignments to ES2015 * Compile shorthand object properties to ES2015 shorthand properties This dramatically improves the appearance of destructured imports. * Compile default values in destructured assignment to ES2015 * Rename `wrapInBraces` to `wrapInParentheses`, and `compilePatternMatch` to `compileDestructuring`, for clarity; style improvements (no `==` or `!=`, etc.) * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Optional check for existence that only checks `!== undefined`, not `!= null`, to follow ES convention that default values only apply when a variable is undefined, not falsy * Add comments; remove unnecessary array splats in function tests * The fallback destructuring code should apply default values only if `undefined`, not falsy, to follow ES spec * Support destructuring in function parameters (first pass); catch destructured reserved words * Destructured variables in function parameter lists shouldn’t be added to the function body with `var` declarations; treat splat array function parameters the legacy way to avoid rethinking #4005 * Remove redundancy in undefined-only check for existence; fix passing option to check * Fix undefined redundancy * Simplify getting the variable name * Reimplement “check for existence if not undefined” without creating a new operator * `Obj::isAssignable` should not mutate; pass `lhs` property in from `Assign` or `Code` to child arrays and objects so that those child nodes are set as allowable for destructuring * Revert changes to tests * Restore revised test for empty destructuring assignment
2017-04-06 17:06:45 +00:00
({Parser} = require('jison'));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Jison DSL
// ---------
// Since we're going to be wrapped in a function by Jison in any case, if our
// action immediately returns a value, we can optimize by removing the function
// wrapper and just returning the value directly.
unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Our handy DSL for Jison grammar generation, thanks to
// [Tim Caswell](https://github.com/creationix). For every rule in the grammar,
// we pass the pattern-defining string, the action to run, and extra options,
// optionally. If no action is specified, we simply pass the value of the
// previous nonterminal.
o = function(patternString, action, options) {
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
var getAddDataToNodeFunctionString, match, patternCount, performActionFunctionString;
patternString = patternString.replace(/\s{2,}/g, ' ');
patternCount = patternString.split(' ').length;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
if (action) {
action = (match = unwrap.exec(action)) ? match[1] : `(${action}())`;
// All runtime functions we need are defined on `yy`
action = action.replace(/\bnew /g, '$&yy.');
action = action.replace(/\b(?:Block\.wrap|extend)\b/g, 'yy.$&');
// Returns strings of functions to add to `parser.js` which add extra data
// that nodes may have, such as comments or location data. Location data
// is added to the first parameter passed in, and the parameter is returned.
// If the parameter is not a node, it will just be passed through unaffected.
getAddDataToNodeFunctionString = function(first, last) {
return `yy.addDataToNode(yy, @${first}${(last ? `, @${last}` : '')})`;
};
action = action.replace(/LOC\(([0-9]*)\)/g, getAddDataToNodeFunctionString('$1'));
action = action.replace(/LOC\(([0-9]*),\s*([0-9]*)\)/g, getAddDataToNodeFunctionString('$1', '$2'));
performActionFunctionString = `$$ = ${getAddDataToNodeFunctionString(1, patternCount)}(${action});`;
} else {
performActionFunctionString = '$$ = $1;';
2012-04-10 18:57:45 +00:00
}
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
return [patternString, performActionFunctionString, options];
2010-02-11 04:24:05 +00:00
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Grammatical Rules
// -----------------
// In all of the rules that follow, you'll see the name of the nonterminal as
// the key to a list of alternative matches. With each match's action, the
// dollar-sign variables are provided by Jison as references to the value of
// their numeric position, so in this rule:
// 'Expression UNLESS Expression'
// `$1` would be the value of the first `Expression`, `$2` would be the token
// for the `UNLESS` terminal, and `$3` would be the value of the second
// `Expression`.
2010-02-11 04:24:05 +00:00
grammar = {
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The **Root** is the top-level node in the syntax tree. Since we parse bottom-up,
// all parsing must end here.
Root: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('',
function() {
2011-01-15 19:19:35 +00:00
return new Block;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Body')
2010-02-11 04:24:05 +00:00
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Any list of statements and expressions, separated by line breaks or semicolons.
Body: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Line',
function() {
2011-01-15 19:19:35 +00:00
return Block.wrap([$1]);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Body TERMINATOR Line',
function() {
2010-02-11 04:24:05 +00:00
return $1.push($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Body TERMINATOR')
2010-04-05 14:26:23 +00:00
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Block and statements, which make up a line in a body. YieldReturn is a
// statement, but not included in Statement because that results in an ambiguous
// grammar.
Line: [o('Expression'), o('ExpressionLine'), o('Statement'), o('FuncDirective')],
FuncDirective: [o('YieldReturn'), o('AwaitReturn')],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Pure statements which cannot be expressions.
Statement: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Return'),
o('STATEMENT',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new StatementLiteral($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Import'),
o('Export')
],
// All the different types of expressions in our language. The basic unit of
// CoffeeScript is the **Expression** -- everything that can be an expression
// is one. Blocks serve as the building blocks of many other rules, making
// them somewhat circular.
Expression: [o('Value'), o('Code'), o('Operation'), o('Assign'), o('If'), o('Try'), o('While'), o('For'), o('Switch'), o('Class'), o('Throw'), o('Yield')],
// Expressions which are written in single line and would otherwise require being
// wrapped in braces: E.g `a = b if do -> f a is 1`, `if f (a) -> a*2 then ...`,
// `for x in do (obj) -> f obj when x > 8 then f x`
ExpressionLine: [o('CodeLine'), o('IfLine'), o('OperationLine')],
Yield: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('YIELD',
function() {
return new Op($1,
new Value(new Literal('')));
}),
o('YIELD Expression',
function() {
return new Op($1,
$2);
}),
o('YIELD INDENT Object OUTDENT',
function() {
return new Op($1,
$3);
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('YIELD FROM Expression',
function() {
return new Op($1.concat($2),
$3);
})
],
// An indented block of expressions. Note that the [Rewriter](rewriter.html)
// will convert some postfix forms into blocks for us, by adjusting the
// token stream.
Block: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('INDENT OUTDENT',
function() {
2011-01-15 19:19:35 +00:00
return new Block;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('INDENT Body OUTDENT',
function() {
2010-02-11 04:24:05 +00:00
return $2;
})
],
Identifier: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('IDENTIFIER',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new IdentifierLiteral($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('CSX_TAG',
function() {
return new CSXTag($1);
2010-02-11 04:24:05 +00:00
})
],
Property: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('PROPERTY',
function() {
return new PropertyName($1);
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Alphanumerics are separated from the other **Literal** matchers because
// they can also serve as keys in object literals.
AlphaNumeric: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('NUMBER',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new NumberLiteral($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('String')
2015-02-07 19:16:59 +00:00
],
String: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('STRING',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new StringLiteral($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('STRING_START Body STRING_END',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new StringWithInterpolations($2);
2015-02-07 19:16:59 +00:00
})
],
Regex: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('REGEX',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new RegexLiteral($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('REGEX_START Invocation REGEX_END',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new RegexWithInterpolations($2.args);
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// All of our immediate values. Generally these can be passed straight
// through and printed to JavaScript.
Literal: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('AlphaNumeric'),
o('JS',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new PassthroughLiteral($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Regex'),
o('UNDEFINED',
function() {
return new UndefinedLiteral($1);
}),
o('NULL',
function() {
return new NullLiteral($1);
}),
o('BOOL',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new BooleanLiteral($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('INFINITY',
function() {
return new InfinityLiteral($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('NAN',
function() {
return new NaNLiteral($1);
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Assignment of a variable, property, or index to a value.
Assign: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Assignable = Expression',
function() {
return new Assign($1,
$3);
}),
o('Assignable = TERMINATOR Expression',
function() {
return new Assign($1,
$4);
}),
o('Assignable = INDENT Expression OUTDENT',
function() {
return new Assign($1,
$4);
})
],
// Assignment when it happens within an object literal. The difference from
// the ordinary **Assign** is that these allow numbers and strings as keys.
AssignObj: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('ObjAssignable',
function() {
2013-02-28 13:37:30 +00:00
return new Value($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ObjRestValue'),
o('ObjAssignable : Expression',
function() {
return new Assign(LOC(1)(new Value($1)),
$3,
'object',
{
operatorToken: LOC(2)(new Literal($2))
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ObjAssignable : INDENT Expression OUTDENT',
function() {
return new Assign(LOC(1)(new Value($1)),
$4,
'object',
{
operatorToken: LOC(2)(new Literal($2))
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('SimpleObjAssignable = Expression',
function() {
return new Assign(LOC(1)(new Value($1)),
$3,
null,
{
operatorToken: LOC(2)(new Literal($2))
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('SimpleObjAssignable = INDENT Expression OUTDENT',
function() {
return new Assign(LOC(1)(new Value($1)),
$4,
null,
{
operatorToken: LOC(2)(new Literal($2))
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
})
2010-02-11 04:24:05 +00:00
],
SimpleObjAssignable: [o('Identifier'), o('Property'), o('ThisProperty')],
ObjAssignable: [
o('SimpleObjAssignable'),
o('[ Expression ]',
function() {
return new Value(new ComputedPropertyName($2));
}),
o('AlphaNumeric')
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Object literal spread properties.
[CS2] Destructuring object spreads (#4493) * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * Correct comment * object destructuring * Allow custom position of the rest element. * Output simple array destructuring assignments to ES2015 * Output simple object destructured assignments to ES2015 * Compile shorthand object properties to ES2015 shorthand properties This dramatically improves the appearance of destructured imports. * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * object destructuring * Allow custom position of the rest element. * rest element in object destructuring * rest element in object destructuring * fix string interpolation * merging * fixing splats in object literal * Rest element in parameter destructuring * merging with CS2 * merged with CS2 * Add support for the object spread initializer. https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md * Fix misspellings, trailing whitespace, other minor details * merging with beta2 * refactor object spread properties * small fix * - Fixed object spread function parameters. - Clean up "Assign" and moved all logic for object rest properties in single method (compileObjectDestruct). - Add helper function "objectWithoutKeys" to the "UTILITIES" for use with object rest properties, e.g. {a, b, r...} = obj => {a, b} = obj, r = objectWithoutKeys(...) - Clean up "Obj" and moved all logic for object spread properties in single method (compileSpread). - Clean up "Code". - Add method "hasSplat" to "Obj" and "Value" for checking if Obj contains the splat. - Enable placing spread syntax triple dots on either right or left, per #85 (https://github.com/coffeescript6/discuss/issues/85) * Fixed typos * Remove unused code * Removed dots (e.g. splat) on the left side from the grammar * Initial release for deep spread properties, e.g. obj2 = {obj.b..., a: 1} or {obj[b][c]..., d: 7} Tests need to be prepared! * 1. Object literal spread properties Object literals: - obj = { {b:{c:{d:1}}}..., a:1 } Parenthetical: - obj = { ( body ), a:1 } - obj = { ( body )..., a:1 } Invocation: - obj = { ( (args) -> ... )(params), a:1 } - obj = { ( (args) -> ... )(params)..., a:1 } - obj = { foo(), a:1 } - obj = { foo()..., a:1 } 2. Refactor, cleanup & other optimizations. * Merged with 2.0 * Cleanup * Some more cleanup. * Fixed error with freeVariable and object destructuring. * Fixed errors with object spread properties. * Improvements, fixed errors. * Minor improvement. * Minor improvements. * Typo. * Remove unnecessary whitespace. * Remove unnecessary whitespace. * Changed few "assertErrorFormat" tests since parentheses are now allowed in the Obj. * Whitespace cleanup * Comments cleanup * fix destructured obj param declarations * refine fix; add test * Refactor function args ({a, b...}) * Additional tests for object destructuring in function argument. * Minor improvement for object destructuring variable declaration. * refactor function args ({a, b...}) and ({a, b...} = {}); Obj And Param cleanup * fix comment * Fix object destructuring variable declaration. * more tests with default values * fix typo * Fixed default values in object destructuring. * small fix * Babel’s tests for object rest spread * Style: spaces after colons in object declarations * Cleanup comments * Simplify Babel tests * Fix comments * Fix destructuring with splats in multiple objects * Add test for default values in detsructuring assignment with splats * Handle default values when assigning to object splats * Rewrite traverseRest to fix handling of dynamic keys * Fix double parens around destructuring with splats * Update compileObjectDestruct comments * Improve formatting of top-level destructures with splats and tidy parens * Added a bigger destructuring-with-defaults test and fixed a bug * Refactor destructuring grammar to allow additional forms * Add a missing case to ObjSpreadExpr * These tests shouldn’t run in the browser * Fix test.html
2017-06-30 05:57:42 +00:00
ObjRestValue: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('SimpleObjAssignable ...',
function() {
[CS2] Destructuring object spreads (#4493) * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * Correct comment * object destructuring * Allow custom position of the rest element. * Output simple array destructuring assignments to ES2015 * Output simple object destructured assignments to ES2015 * Compile shorthand object properties to ES2015 shorthand properties This dramatically improves the appearance of destructured imports. * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * object destructuring * Allow custom position of the rest element. * rest element in object destructuring * rest element in object destructuring * fix string interpolation * merging * fixing splats in object literal * Rest element in parameter destructuring * merging with CS2 * merged with CS2 * Add support for the object spread initializer. https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md * Fix misspellings, trailing whitespace, other minor details * merging with beta2 * refactor object spread properties * small fix * - Fixed object spread function parameters. - Clean up "Assign" and moved all logic for object rest properties in single method (compileObjectDestruct). - Add helper function "objectWithoutKeys" to the "UTILITIES" for use with object rest properties, e.g. {a, b, r...} = obj => {a, b} = obj, r = objectWithoutKeys(...) - Clean up "Obj" and moved all logic for object spread properties in single method (compileSpread). - Clean up "Code". - Add method "hasSplat" to "Obj" and "Value" for checking if Obj contains the splat. - Enable placing spread syntax triple dots on either right or left, per #85 (https://github.com/coffeescript6/discuss/issues/85) * Fixed typos * Remove unused code * Removed dots (e.g. splat) on the left side from the grammar * Initial release for deep spread properties, e.g. obj2 = {obj.b..., a: 1} or {obj[b][c]..., d: 7} Tests need to be prepared! * 1. Object literal spread properties Object literals: - obj = { {b:{c:{d:1}}}..., a:1 } Parenthetical: - obj = { ( body ), a:1 } - obj = { ( body )..., a:1 } Invocation: - obj = { ( (args) -> ... )(params), a:1 } - obj = { ( (args) -> ... )(params)..., a:1 } - obj = { foo(), a:1 } - obj = { foo()..., a:1 } 2. Refactor, cleanup & other optimizations. * Merged with 2.0 * Cleanup * Some more cleanup. * Fixed error with freeVariable and object destructuring. * Fixed errors with object spread properties. * Improvements, fixed errors. * Minor improvement. * Minor improvements. * Typo. * Remove unnecessary whitespace. * Remove unnecessary whitespace. * Changed few "assertErrorFormat" tests since parentheses are now allowed in the Obj. * Whitespace cleanup * Comments cleanup * fix destructured obj param declarations * refine fix; add test * Refactor function args ({a, b...}) * Additional tests for object destructuring in function argument. * Minor improvement for object destructuring variable declaration. * refactor function args ({a, b...}) and ({a, b...} = {}); Obj And Param cleanup * fix comment * Fix object destructuring variable declaration. * more tests with default values * fix typo * Fixed default values in object destructuring. * small fix * Babel’s tests for object rest spread * Style: spaces after colons in object declarations * Cleanup comments * Simplify Babel tests * Fix comments * Fix destructuring with splats in multiple objects * Add test for default values in detsructuring assignment with splats * Handle default values when assigning to object splats * Rewrite traverseRest to fix handling of dynamic keys * Fix double parens around destructuring with splats * Update compileObjectDestruct comments * Improve formatting of top-level destructures with splats and tidy parens * Added a bigger destructuring-with-defaults test and fixed a bug * Refactor destructuring grammar to allow additional forms * Add a missing case to ObjSpreadExpr * These tests shouldn’t run in the browser * Fix test.html
2017-06-30 05:57:42 +00:00
return new Splat(new Value($1));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('... SimpleObjAssignable',
function() {
return new Splat(new Value($2));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ObjSpreadExpr ...',
function() {
[CS2] Destructuring object spreads (#4493) * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * Correct comment * object destructuring * Allow custom position of the rest element. * Output simple array destructuring assignments to ES2015 * Output simple object destructured assignments to ES2015 * Compile shorthand object properties to ES2015 shorthand properties This dramatically improves the appearance of destructured imports. * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * object destructuring * Allow custom position of the rest element. * rest element in object destructuring * rest element in object destructuring * fix string interpolation * merging * fixing splats in object literal * Rest element in parameter destructuring * merging with CS2 * merged with CS2 * Add support for the object spread initializer. https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md * Fix misspellings, trailing whitespace, other minor details * merging with beta2 * refactor object spread properties * small fix * - Fixed object spread function parameters. - Clean up "Assign" and moved all logic for object rest properties in single method (compileObjectDestruct). - Add helper function "objectWithoutKeys" to the "UTILITIES" for use with object rest properties, e.g. {a, b, r...} = obj => {a, b} = obj, r = objectWithoutKeys(...) - Clean up "Obj" and moved all logic for object spread properties in single method (compileSpread). - Clean up "Code". - Add method "hasSplat" to "Obj" and "Value" for checking if Obj contains the splat. - Enable placing spread syntax triple dots on either right or left, per #85 (https://github.com/coffeescript6/discuss/issues/85) * Fixed typos * Remove unused code * Removed dots (e.g. splat) on the left side from the grammar * Initial release for deep spread properties, e.g. obj2 = {obj.b..., a: 1} or {obj[b][c]..., d: 7} Tests need to be prepared! * 1. Object literal spread properties Object literals: - obj = { {b:{c:{d:1}}}..., a:1 } Parenthetical: - obj = { ( body ), a:1 } - obj = { ( body )..., a:1 } Invocation: - obj = { ( (args) -> ... )(params), a:1 } - obj = { ( (args) -> ... )(params)..., a:1 } - obj = { foo(), a:1 } - obj = { foo()..., a:1 } 2. Refactor, cleanup & other optimizations. * Merged with 2.0 * Cleanup * Some more cleanup. * Fixed error with freeVariable and object destructuring. * Fixed errors with object spread properties. * Improvements, fixed errors. * Minor improvement. * Minor improvements. * Typo. * Remove unnecessary whitespace. * Remove unnecessary whitespace. * Changed few "assertErrorFormat" tests since parentheses are now allowed in the Obj. * Whitespace cleanup * Comments cleanup * fix destructured obj param declarations * refine fix; add test * Refactor function args ({a, b...}) * Additional tests for object destructuring in function argument. * Minor improvement for object destructuring variable declaration. * refactor function args ({a, b...}) and ({a, b...} = {}); Obj And Param cleanup * fix comment * Fix object destructuring variable declaration. * more tests with default values * fix typo * Fixed default values in object destructuring. * small fix * Babel’s tests for object rest spread * Style: spaces after colons in object declarations * Cleanup comments * Simplify Babel tests * Fix comments * Fix destructuring with splats in multiple objects * Add test for default values in detsructuring assignment with splats * Handle default values when assigning to object splats * Rewrite traverseRest to fix handling of dynamic keys * Fix double parens around destructuring with splats * Update compileObjectDestruct comments * Improve formatting of top-level destructures with splats and tidy parens * Added a bigger destructuring-with-defaults test and fixed a bug * Refactor destructuring grammar to allow additional forms * Add a missing case to ObjSpreadExpr * These tests shouldn’t run in the browser * Fix test.html
2017-06-30 05:57:42 +00:00
return new Splat($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('... ObjSpreadExpr',
function() {
return new Splat($2);
[CS2] Destructuring object spreads (#4493) * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * Correct comment * object destructuring * Allow custom position of the rest element. * Output simple array destructuring assignments to ES2015 * Output simple object destructured assignments to ES2015 * Compile shorthand object properties to ES2015 shorthand properties This dramatically improves the appearance of destructured imports. * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * object destructuring * Allow custom position of the rest element. * rest element in object destructuring * rest element in object destructuring * fix string interpolation * merging * fixing splats in object literal * Rest element in parameter destructuring * merging with CS2 * merged with CS2 * Add support for the object spread initializer. https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md * Fix misspellings, trailing whitespace, other minor details * merging with beta2 * refactor object spread properties * small fix * - Fixed object spread function parameters. - Clean up "Assign" and moved all logic for object rest properties in single method (compileObjectDestruct). - Add helper function "objectWithoutKeys" to the "UTILITIES" for use with object rest properties, e.g. {a, b, r...} = obj => {a, b} = obj, r = objectWithoutKeys(...) - Clean up "Obj" and moved all logic for object spread properties in single method (compileSpread). - Clean up "Code". - Add method "hasSplat" to "Obj" and "Value" for checking if Obj contains the splat. - Enable placing spread syntax triple dots on either right or left, per #85 (https://github.com/coffeescript6/discuss/issues/85) * Fixed typos * Remove unused code * Removed dots (e.g. splat) on the left side from the grammar * Initial release for deep spread properties, e.g. obj2 = {obj.b..., a: 1} or {obj[b][c]..., d: 7} Tests need to be prepared! * 1. Object literal spread properties Object literals: - obj = { {b:{c:{d:1}}}..., a:1 } Parenthetical: - obj = { ( body ), a:1 } - obj = { ( body )..., a:1 } Invocation: - obj = { ( (args) -> ... )(params), a:1 } - obj = { ( (args) -> ... )(params)..., a:1 } - obj = { foo(), a:1 } - obj = { foo()..., a:1 } 2. Refactor, cleanup & other optimizations. * Merged with 2.0 * Cleanup * Some more cleanup. * Fixed error with freeVariable and object destructuring. * Fixed errors with object spread properties. * Improvements, fixed errors. * Minor improvement. * Minor improvements. * Typo. * Remove unnecessary whitespace. * Remove unnecessary whitespace. * Changed few "assertErrorFormat" tests since parentheses are now allowed in the Obj. * Whitespace cleanup * Comments cleanup * fix destructured obj param declarations * refine fix; add test * Refactor function args ({a, b...}) * Additional tests for object destructuring in function argument. * Minor improvement for object destructuring variable declaration. * refactor function args ({a, b...}) and ({a, b...} = {}); Obj And Param cleanup * fix comment * Fix object destructuring variable declaration. * more tests with default values * fix typo * Fixed default values in object destructuring. * small fix * Babel’s tests for object rest spread * Style: spaces after colons in object declarations * Cleanup comments * Simplify Babel tests * Fix comments * Fix destructuring with splats in multiple objects * Add test for default values in detsructuring assignment with splats * Handle default values when assigning to object splats * Rewrite traverseRest to fix handling of dynamic keys * Fix double parens around destructuring with splats * Update compileObjectDestruct comments * Improve formatting of top-level destructures with splats and tidy parens * Added a bigger destructuring-with-defaults test and fixed a bug * Refactor destructuring grammar to allow additional forms * Add a missing case to ObjSpreadExpr * These tests shouldn’t run in the browser * Fix test.html
2017-06-30 05:57:42 +00:00
})
],
ObjSpreadExpr: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('ObjSpreadIdentifier'),
o('Object'),
o('Parenthetical'),
o('Super'),
o('This'),
o('SUPER Arguments',
function() {
return new SuperCall(LOC(1)(new Super),
$2,
false,
$1);
}),
o('DYNAMIC_IMPORT Arguments',
function() {
return new DynamicImportCall(LOC(1)(new DynamicImport),
$2);
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('SimpleObjAssignable Arguments',
function() {
return new Call(new Value($1),
$2);
}),
o('ObjSpreadExpr Arguments',
function() {
return new Call($1,
$2);
[CS2] Destructuring object spreads (#4493) * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * Correct comment * object destructuring * Allow custom position of the rest element. * Output simple array destructuring assignments to ES2015 * Output simple object destructured assignments to ES2015 * Compile shorthand object properties to ES2015 shorthand properties This dramatically improves the appearance of destructured imports. * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * object destructuring * Allow custom position of the rest element. * rest element in object destructuring * rest element in object destructuring * fix string interpolation * merging * fixing splats in object literal * Rest element in parameter destructuring * merging with CS2 * merged with CS2 * Add support for the object spread initializer. https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md * Fix misspellings, trailing whitespace, other minor details * merging with beta2 * refactor object spread properties * small fix * - Fixed object spread function parameters. - Clean up "Assign" and moved all logic for object rest properties in single method (compileObjectDestruct). - Add helper function "objectWithoutKeys" to the "UTILITIES" for use with object rest properties, e.g. {a, b, r...} = obj => {a, b} = obj, r = objectWithoutKeys(...) - Clean up "Obj" and moved all logic for object spread properties in single method (compileSpread). - Clean up "Code". - Add method "hasSplat" to "Obj" and "Value" for checking if Obj contains the splat. - Enable placing spread syntax triple dots on either right or left, per #85 (https://github.com/coffeescript6/discuss/issues/85) * Fixed typos * Remove unused code * Removed dots (e.g. splat) on the left side from the grammar * Initial release for deep spread properties, e.g. obj2 = {obj.b..., a: 1} or {obj[b][c]..., d: 7} Tests need to be prepared! * 1. Object literal spread properties Object literals: - obj = { {b:{c:{d:1}}}..., a:1 } Parenthetical: - obj = { ( body ), a:1 } - obj = { ( body )..., a:1 } Invocation: - obj = { ( (args) -> ... )(params), a:1 } - obj = { ( (args) -> ... )(params)..., a:1 } - obj = { foo(), a:1 } - obj = { foo()..., a:1 } 2. Refactor, cleanup & other optimizations. * Merged with 2.0 * Cleanup * Some more cleanup. * Fixed error with freeVariable and object destructuring. * Fixed errors with object spread properties. * Improvements, fixed errors. * Minor improvement. * Minor improvements. * Typo. * Remove unnecessary whitespace. * Remove unnecessary whitespace. * Changed few "assertErrorFormat" tests since parentheses are now allowed in the Obj. * Whitespace cleanup * Comments cleanup * fix destructured obj param declarations * refine fix; add test * Refactor function args ({a, b...}) * Additional tests for object destructuring in function argument. * Minor improvement for object destructuring variable declaration. * refactor function args ({a, b...}) and ({a, b...} = {}); Obj And Param cleanup * fix comment * Fix object destructuring variable declaration. * more tests with default values * fix typo * Fixed default values in object destructuring. * small fix * Babel’s tests for object rest spread * Style: spaces after colons in object declarations * Cleanup comments * Simplify Babel tests * Fix comments * Fix destructuring with splats in multiple objects * Add test for default values in detsructuring assignment with splats * Handle default values when assigning to object splats * Rewrite traverseRest to fix handling of dynamic keys * Fix double parens around destructuring with splats * Update compileObjectDestruct comments * Improve formatting of top-level destructures with splats and tidy parens * Added a bigger destructuring-with-defaults test and fixed a bug * Refactor destructuring grammar to allow additional forms * Add a missing case to ObjSpreadExpr * These tests shouldn’t run in the browser * Fix test.html
2017-06-30 05:57:42 +00:00
})
],
ObjSpreadIdentifier: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('SimpleObjAssignable ObjSpreadAccessor',
function() {
return (new Value($1)).add($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ObjSpreadExpr ObjSpreadAccessor',
function() {
return (new Value($1)).add($2);
})
],
ObjSpreadAccessor: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('. Property',
function() {
return new Access($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('INDEX_START IndexValue INDEX_END',
function() {
return $2;
[CS2] Destructuring object spreads (#4493) * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * Correct comment * object destructuring * Allow custom position of the rest element. * Output simple array destructuring assignments to ES2015 * Output simple object destructured assignments to ES2015 * Compile shorthand object properties to ES2015 shorthand properties This dramatically improves the appearance of destructured imports. * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * object destructuring * Allow custom position of the rest element. * rest element in object destructuring * rest element in object destructuring * fix string interpolation * merging * fixing splats in object literal * Rest element in parameter destructuring * merging with CS2 * merged with CS2 * Add support for the object spread initializer. https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md * Fix misspellings, trailing whitespace, other minor details * merging with beta2 * refactor object spread properties * small fix * - Fixed object spread function parameters. - Clean up "Assign" and moved all logic for object rest properties in single method (compileObjectDestruct). - Add helper function "objectWithoutKeys" to the "UTILITIES" for use with object rest properties, e.g. {a, b, r...} = obj => {a, b} = obj, r = objectWithoutKeys(...) - Clean up "Obj" and moved all logic for object spread properties in single method (compileSpread). - Clean up "Code". - Add method "hasSplat" to "Obj" and "Value" for checking if Obj contains the splat. - Enable placing spread syntax triple dots on either right or left, per #85 (https://github.com/coffeescript6/discuss/issues/85) * Fixed typos * Remove unused code * Removed dots (e.g. splat) on the left side from the grammar * Initial release for deep spread properties, e.g. obj2 = {obj.b..., a: 1} or {obj[b][c]..., d: 7} Tests need to be prepared! * 1. Object literal spread properties Object literals: - obj = { {b:{c:{d:1}}}..., a:1 } Parenthetical: - obj = { ( body ), a:1 } - obj = { ( body )..., a:1 } Invocation: - obj = { ( (args) -> ... )(params), a:1 } - obj = { ( (args) -> ... )(params)..., a:1 } - obj = { foo(), a:1 } - obj = { foo()..., a:1 } 2. Refactor, cleanup & other optimizations. * Merged with 2.0 * Cleanup * Some more cleanup. * Fixed error with freeVariable and object destructuring. * Fixed errors with object spread properties. * Improvements, fixed errors. * Minor improvement. * Minor improvements. * Typo. * Remove unnecessary whitespace. * Remove unnecessary whitespace. * Changed few "assertErrorFormat" tests since parentheses are now allowed in the Obj. * Whitespace cleanup * Comments cleanup * fix destructured obj param declarations * refine fix; add test * Refactor function args ({a, b...}) * Additional tests for object destructuring in function argument. * Minor improvement for object destructuring variable declaration. * refactor function args ({a, b...}) and ({a, b...} = {}); Obj And Param cleanup * fix comment * Fix object destructuring variable declaration. * more tests with default values * fix typo * Fixed default values in object destructuring. * small fix * Babel’s tests for object rest spread * Style: spaces after colons in object declarations * Cleanup comments * Simplify Babel tests * Fix comments * Fix destructuring with splats in multiple objects * Add test for default values in detsructuring assignment with splats * Handle default values when assigning to object splats * Rewrite traverseRest to fix handling of dynamic keys * Fix double parens around destructuring with splats * Update compileObjectDestruct comments * Improve formatting of top-level destructures with splats and tidy parens * Added a bigger destructuring-with-defaults test and fixed a bug * Refactor destructuring grammar to allow additional forms * Add a missing case to ObjSpreadExpr * These tests shouldn’t run in the browser * Fix test.html
2017-06-30 05:57:42 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// A return statement from a function body.
Return: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('RETURN Expression',
function() {
return new Return($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('RETURN INDENT Object OUTDENT',
function() {
return new Return(new Value($3));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('RETURN',
function() {
return new Return;
2010-02-11 04:24:05 +00:00
})
],
YieldReturn: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('YIELD RETURN Expression',
function() {
return new YieldReturn($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('YIELD RETURN',
function() {
return new YieldReturn;
})
],
AwaitReturn: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('AWAIT RETURN Expression',
function() {
return new AwaitReturn($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('AWAIT RETURN',
function() {
return new AwaitReturn;
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The **Code** node is the function literal. It's defined by an indented block
// of **Block** preceded by a function arrow, with an optional parameter list.
Code: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('PARAM_START ParamList PARAM_END FuncGlyph Block',
function() {
return new Code($2,
$5,
$4,
LOC(1)(new Literal($1)));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FuncGlyph Block',
function() {
return new Code([],
$2,
$1);
})
],
// The Codeline is the **Code** node with **Line** instead of indented **Block**.
CodeLine: [
o('PARAM_START ParamList PARAM_END FuncGlyph Line',
function() {
return new Code($2,
LOC(5)(Block.wrap([$5])),
$4,
LOC(1)(new Literal($1)));
}),
o('FuncGlyph Line',
function() {
return new Code([],
LOC(2)(Block.wrap([$2])),
$1);
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// CoffeeScript has two different symbols for functions. `->` is for ordinary
// functions, and `=>` is for functions bound to the current value of *this*.
FuncGlyph: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('->',
function() {
return new FuncGlyph($1);
}),
o('=>',
function() {
return new FuncGlyph($1);
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// An optional, trailing comma.
OptComma: [o(''), o(',')],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The list of parameters that a function accepts can be of any length.
ParamList: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('',
function() {
return [];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Param',
function() {
2010-02-11 04:24:05 +00:00
return [$1];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ParamList , Param',
function() {
2010-10-11 07:06:29 +00:00
return $1.concat($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ParamList OptComma TERMINATOR Param',
function() {
return $1.concat($4);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ParamList OptComma INDENT ParamList OptComma OUTDENT',
function() {
return $1.concat($4);
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// A single parameter in a function definition can be ordinary, or a splat
// that hoovers up the remaining arguments.
Param: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('ParamVar',
function() {
2010-10-26 04:09:46 +00:00
return new Param($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ParamVar ...',
function() {
return new Param($1,
null,
true);
}),
o('... ParamVar',
function() {
return new Param($2,
null,
true);
}),
o('ParamVar = Expression',
function() {
return new Param($1,
$3);
}),
o('...',
function() {
2014-01-24 16:00:34 +00:00
return new Expansion;
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Function Parameters
ParamVar: [o('Identifier'), o('ThisProperty'), o('Array'), o('Object')],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// A splat that occurs outside of a parameter list.
Splat: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Expression ...',
function() {
return new Splat($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('... Expression',
function() {
return new Splat($2);
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Variables and properties that can be assigned to.
SimpleAssignable: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Identifier',
function() {
2013-02-28 13:37:30 +00:00
return new Value($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Value Accessor',
function() {
return $1.add($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Code Accessor',
function() {
return new Value($1).add($2);
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('ThisProperty')
2010-03-28 17:06:16 +00:00
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Everything that can be assigned to.
Assignable: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('SimpleAssignable'),
o('Array',
function() {
2013-02-28 13:37:30 +00:00
return new Value($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Object',
function() {
2013-02-28 13:37:30 +00:00
return new Value($1);
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The types of things that can be treated as values -- assigned to, invoked
// as functions, indexed into, named as a class, etc.
Value: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Assignable'),
o('Literal',
function() {
2013-02-28 13:37:30 +00:00
return new Value($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Parenthetical',
function() {
2013-02-28 13:37:30 +00:00
return new Value($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Range',
function() {
2013-02-28 13:37:30 +00:00
return new Value($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Invocation',
function() {
return new Value($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('This'),
o('Super',
function() {
return new Value($1);
})
[CS2] Compile all super calls to ES2015 super (#4424) * Compile all super calls to ES2015 super This breaks using `super` in non-methods, meaning several tests are failing. Self-compilation still works. * Use bound functions for IIFEs containing `super` `super` can only be called directly in a method, or in an arrow function. * Fix handling of `class @A extends A` This behaviour worked 'for free' when the parent reference was being cached by the executable class body wrapper. There now needs to be special handling in place to check if the parent name matches the class name, and if so to cache the parent reference. * Fix tests broken by compiling ES2015 `super` * Disallow bare super This removes syntax support for 'bare' super calls, e.g.: class B extends A constructor: -> super `super` must now always be followed with arguments like a regular function call. This also removes the capability of implicitly forwarding arguments. The above can be equivalently be written as: class B extends A constructor: -> super arguments... * Support super with accessors `super` with following accessor(s) is now compiled to ES2015 equivalents. In particular, expressions such as `super.name`, `super[name]`, and also `super.name.prop` are all now valid, and can be used as expected as calls (i.e. `super.name()`) or in expressions (i.e. `if super.name? ...`). `super` without accessors is compiled to a constructor super call in a constructor, and otherwise, as before, to a super call to the method of the same name, i.e. speak: -> super() ...is equivalent to speak: -> super.speak() A neat side-effect of the changes is that existential calls now work properly with super, meaning `super?()` will only call if the super property exists (and is a function). This is not valid for super in constructors. * Prevent calling `super` methods with `new` This fixes a bug in the previous super handling whereby using the `new` operator with a `super` call would silently drop the `new`. This is now an explicit compiler error, as it is invalid JS at runtime. * Clean up some old super handling code This was mostly code for tracking the source classes and variables for methods, which were needed to build the old lookups on `__super__`. * Add TODO to improve bare super parse error * Add some TODOs to improve some of the class tests
2017-02-04 20:03:17 +00:00
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// A `super`-based expression that can be used as a value.
[CS2] Compile all super calls to ES2015 super (#4424) * Compile all super calls to ES2015 super This breaks using `super` in non-methods, meaning several tests are failing. Self-compilation still works. * Use bound functions for IIFEs containing `super` `super` can only be called directly in a method, or in an arrow function. * Fix handling of `class @A extends A` This behaviour worked 'for free' when the parent reference was being cached by the executable class body wrapper. There now needs to be special handling in place to check if the parent name matches the class name, and if so to cache the parent reference. * Fix tests broken by compiling ES2015 `super` * Disallow bare super This removes syntax support for 'bare' super calls, e.g.: class B extends A constructor: -> super `super` must now always be followed with arguments like a regular function call. This also removes the capability of implicitly forwarding arguments. The above can be equivalently be written as: class B extends A constructor: -> super arguments... * Support super with accessors `super` with following accessor(s) is now compiled to ES2015 equivalents. In particular, expressions such as `super.name`, `super[name]`, and also `super.name.prop` are all now valid, and can be used as expected as calls (i.e. `super.name()`) or in expressions (i.e. `if super.name? ...`). `super` without accessors is compiled to a constructor super call in a constructor, and otherwise, as before, to a super call to the method of the same name, i.e. speak: -> super() ...is equivalent to speak: -> super.speak() A neat side-effect of the changes is that existential calls now work properly with super, meaning `super?()` will only call if the super property exists (and is a function). This is not valid for super in constructors. * Prevent calling `super` methods with `new` This fixes a bug in the previous super handling whereby using the `new` operator with a `super` call would silently drop the `new`. This is now an explicit compiler error, as it is invalid JS at runtime. * Clean up some old super handling code This was mostly code for tracking the source classes and variables for methods, which were needed to build the old lookups on `__super__`. * Add TODO to improve bare super parse error * Add some TODOs to improve some of the class tests
2017-02-04 20:03:17 +00:00
Super: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('SUPER . Property',
function() {
return new Super(LOC(3)(new Access($3)),
[],
false,
$1);
}),
o('SUPER INDEX_START Expression INDEX_END',
function() {
return new Super(LOC(3)(new Index($3)),
[],
false,
$1);
})
],
// The general group of accessors into an object, by property, by prototype
// or by array index or slice.
Accessor: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('. Property',
function() {
2010-11-21 01:09:36 +00:00
return new Access($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('?. Property',
function() {
return new Access($2,
'soak');
}),
o(':: Property',
function() {
return [LOC(1)(new Access(new PropertyName('prototype'))),
LOC(2)(new Access($2))];
}),
o('?:: Property',
function() {
return [LOC(1)(new Access(new PropertyName('prototype'),
'soak')),
LOC(2)(new Access($2))];
}),
o('::',
function() {
return new Access(new PropertyName('prototype'));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('?::',
function() {
return new Access(new PropertyName('prototype'),
'soak');
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Index')
2010-02-11 04:24:05 +00:00
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Indexing into an object or array using bracket notation.
Index: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('INDEX_START IndexValue INDEX_END',
function() {
return $2;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('INDEX_SOAK Index',
function() {
return extend($2,
{
2010-10-25 13:31:52 +00:00
soak: true
});
2010-02-11 04:24:05 +00:00
})
],
IndexValue: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Expression',
function() {
return new Index($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Slice',
function() {
return new Slice($1);
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// In CoffeeScript, an object literal is simply a list of assignments.
Object: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('{ AssignList OptComma }',
function() {
return new Obj($2,
$1.generated);
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Assignment of properties within an object literal can be separated by
// comma, as in JavaScript, or simply by newline.
AssignList: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('',
function() {
2010-02-11 04:24:05 +00:00
return [];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('AssignObj',
function() {
2010-02-11 04:24:05 +00:00
return [$1];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('AssignList , AssignObj',
function() {
2010-10-11 07:06:29 +00:00
return $1.concat($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('AssignList OptComma TERMINATOR AssignObj',
function() {
2010-10-11 07:06:29 +00:00
return $1.concat($4);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('AssignList OptComma INDENT AssignList OptComma OUTDENT',
function() {
return $1.concat($4);
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Class definitions have optional bodies of prototype property assignments,
// and optional references to the superclass.
Class: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('CLASS',
function() {
return new Class;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('CLASS Block',
function() {
return new Class(null,
null,
$2);
}),
o('CLASS EXTENDS Expression',
function() {
return new Class(null,
$3);
}),
o('CLASS EXTENDS Expression Block',
function() {
return new Class(null,
$3,
$4);
}),
o('CLASS SimpleAssignable',
function() {
return new Class($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('CLASS SimpleAssignable Block',
function() {
return new Class($2,
null,
$3);
}),
o('CLASS SimpleAssignable EXTENDS Expression',
function() {
return new Class($2,
$4);
}),
o('CLASS SimpleAssignable EXTENDS Expression Block',
function() {
return new Class($2,
$4,
$5);
})
2010-02-11 04:24:05 +00:00
],
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
Import: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('IMPORT String',
function() {
return new ImportDeclaration(null,
$2);
}),
o('IMPORT ImportDefaultSpecifier FROM String',
function() {
return new ImportDeclaration(new ImportClause($2,
null),
$4);
}),
o('IMPORT ImportNamespaceSpecifier FROM String',
function() {
return new ImportDeclaration(new ImportClause(null,
$2),
$4);
}),
o('IMPORT { } FROM String',
function() {
return new ImportDeclaration(new ImportClause(null,
new ImportSpecifierList([])),
$5);
}),
o('IMPORT { ImportSpecifierList OptComma } FROM String',
function() {
return new ImportDeclaration(new ImportClause(null,
new ImportSpecifierList($3)),
$7);
}),
o('IMPORT ImportDefaultSpecifier , ImportNamespaceSpecifier FROM String',
function() {
return new ImportDeclaration(new ImportClause($2,
$4),
$6);
}),
o('IMPORT ImportDefaultSpecifier , { ImportSpecifierList OptComma } FROM String',
function() {
return new ImportDeclaration(new ImportClause($2,
new ImportSpecifierList($5)),
$9);
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
})
],
ImportSpecifierList: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('ImportSpecifier',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return [$1];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ImportSpecifierList , ImportSpecifier',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return $1.concat($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ImportSpecifierList OptComma TERMINATOR ImportSpecifier',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return $1.concat($4);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('INDENT ImportSpecifierList OptComma OUTDENT',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return $2;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ImportSpecifierList OptComma INDENT ImportSpecifierList OptComma OUTDENT',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return $1.concat($4);
})
],
ImportSpecifier: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Identifier',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return new ImportSpecifier($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Identifier AS Identifier',
function() {
return new ImportSpecifier($1,
$3);
}),
o('DEFAULT',
function() {
return new ImportSpecifier(new Literal($1));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('DEFAULT AS Identifier',
function() {
return new ImportSpecifier(new Literal($1),
$3);
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
})
],
ImportDefaultSpecifier: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Identifier',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return new ImportDefaultSpecifier($1);
})
],
ImportNamespaceSpecifier: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('IMPORT_ALL AS Identifier',
function() {
return new ImportNamespaceSpecifier(new Literal($1),
$3);
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
})
],
Export: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('EXPORT { }',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return new ExportNamedDeclaration(new ExportSpecifierList([]));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('EXPORT { ExportSpecifierList OptComma }',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return new ExportNamedDeclaration(new ExportSpecifierList($3));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('EXPORT Class',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return new ExportNamedDeclaration($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('EXPORT Identifier = Expression',
function() {
return new ExportNamedDeclaration(new Assign($2,
$4,
null,
{
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
moduleDeclaration: 'export'
}));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('EXPORT Identifier = TERMINATOR Expression',
function() {
return new ExportNamedDeclaration(new Assign($2,
$5,
null,
{
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
moduleDeclaration: 'export'
}));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('EXPORT Identifier = INDENT Expression OUTDENT',
function() {
return new ExportNamedDeclaration(new Assign($2,
$5,
null,
{
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
moduleDeclaration: 'export'
}));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('EXPORT DEFAULT Expression',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return new ExportDefaultDeclaration($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('EXPORT DEFAULT INDENT Object OUTDENT',
function() {
return new ExportDefaultDeclaration(new Value($4));
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('EXPORT EXPORT_ALL FROM String',
function() {
return new ExportAllDeclaration(new Literal($2),
$4);
}),
o('EXPORT { ExportSpecifierList OptComma } FROM String',
function() {
return new ExportNamedDeclaration(new ExportSpecifierList($3),
$7);
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
})
],
ExportSpecifierList: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('ExportSpecifier',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return [$1];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ExportSpecifierList , ExportSpecifier',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return $1.concat($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ExportSpecifierList OptComma TERMINATOR ExportSpecifier',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return $1.concat($4);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('INDENT ExportSpecifierList OptComma OUTDENT',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return $2;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ExportSpecifierList OptComma INDENT ExportSpecifierList OptComma OUTDENT',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return $1.concat($4);
})
],
ExportSpecifier: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Identifier',
function() {
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
return new ExportSpecifier($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Identifier AS Identifier',
function() {
return new ExportSpecifier($1,
$3);
}),
o('Identifier AS DEFAULT',
function() {
return new ExportSpecifier($1,
new Literal($3));
}),
o('DEFAULT',
function() {
return new ExportSpecifier(new Literal($1));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('DEFAULT AS Identifier',
function() {
return new ExportSpecifier(new Literal($1),
$3);
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 18:46:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Ordinary function invocation, or a chained series of calls.
Invocation: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Value OptFuncExist String',
function() {
return new TaggedTemplateCall($1,
$3,
$2);
}),
o('Value OptFuncExist Arguments',
function() {
return new Call($1,
$3,
$2);
}),
o('SUPER OptFuncExist Arguments',
function() {
return new SuperCall(LOC(1)(new Super),
$3,
$2,
$1);
}),
o('DYNAMIC_IMPORT Arguments',
function() {
return new DynamicImportCall(LOC(1)(new DynamicImport),
$2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
})
],
// An optional existence check on a function.
OptFuncExist: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('',
function() {
return false;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FUNC_EXIST',
function() {
return true;
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The list of arguments to a function call.
Arguments: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('CALL_START CALL_END',
function() {
return [];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('CALL_START ArgList OptComma CALL_END',
function() {
return $2;
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// A reference to the *this* current object.
This: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('THIS',
function() {
return new Value(new ThisLiteral($1));
}),
o('@',
function() {
return new Value(new ThisLiteral($1));
2010-03-28 17:06:16 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// A reference to a property on *this*.
ThisProperty: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('@ Property',
function() {
return new Value(LOC(1)(new ThisLiteral($1)),
[LOC(2)(new Access($2))],
'this');
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The array literal.
Array: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('[ ]',
function() {
return new Arr([]);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('[ Elisions ]',
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
function() {
return new Arr($2);
}),
o('[ ArgElisionList OptElisions ]',
function() {
return new Arr([].concat($2,
$3));
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Inclusive and exclusive range dots.
2010-11-20 21:25:22 +00:00
RangeDots: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('..',
function() {
2010-11-20 21:25:22 +00:00
return 'inclusive';
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('...',
function() {
2010-11-20 21:25:22 +00:00
return 'exclusive';
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The CoffeeScript range literal.
2010-11-20 21:25:22 +00:00
Range: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('[ Expression RangeDots Expression ]',
function() {
return new Range($2,
$4,
$3);
}),
o('[ ExpressionLine RangeDots Expression ]',
function() {
return new Range($2,
$4,
$3);
2010-11-20 21:25:22 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Array slice literals.
2010-11-20 21:25:22 +00:00
Slice: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Expression RangeDots Expression',
function() {
return new Range($1,
$3,
$2);
}),
o('Expression RangeDots',
function() {
return new Range($1,
null,
$2);
}),
o('ExpressionLine RangeDots Expression',
function() {
return new Range($1,
$3,
$2);
}),
o('ExpressionLine RangeDots',
function() {
return new Range($1,
null,
$2);
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('RangeDots Expression',
function() {
return new Range(null,
$2,
$1);
}),
o('RangeDots',
function() {
return new Range(null,
null,
$1);
})
],
// The **ArgList** is the list of objects passed into a function call
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// (i.e. comma-separated expressions). Newlines work as well.
ArgList: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Arg',
function() {
2010-02-11 04:24:05 +00:00
return [$1];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ArgList , Arg',
function() {
2010-10-11 07:06:29 +00:00
return $1.concat($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ArgList OptComma TERMINATOR Arg',
function() {
2010-10-11 07:06:29 +00:00
return $1.concat($4);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('INDENT ArgList OptComma OUTDENT',
function() {
return $2;
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ArgList OptComma INDENT ArgList OptComma OUTDENT',
function() {
return $1.concat($4);
})
2010-02-11 04:24:05 +00:00
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Valid arguments are Blocks or Splats.
2014-01-24 16:00:34 +00:00
Arg: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Expression'),
o('ExpressionLine'),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Splat'),
o('...',
function() {
2014-01-24 16:00:34 +00:00
return new Expansion;
})
],
// The **ArgElisionList** is the list of objects, contents of an array literal
// (i.e. comma-separated expressions and elisions). Newlines work as well.
ArgElisionList: [
o('ArgElision'),
o('ArgElisionList , ArgElision',
function() {
return $1.concat($3);
}),
o('ArgElisionList OptElisions TERMINATOR ArgElision',
function() {
return $1.concat($2,
$4);
}),
o('INDENT ArgElisionList OptElisions OUTDENT',
function() {
return $2.concat($3);
}),
o('ArgElisionList OptElisions INDENT ArgElisionList OptElisions OUTDENT',
function() {
return $1.concat($2,
$4,
$5);
})
],
ArgElision: [
o('Arg',
function() {
return [$1];
}),
o('Elisions Arg',
function() {
return $1.concat($2);
})
],
OptElisions: [
o('OptComma',
function() {
return [];
}),
o(', Elisions',
function() {
return [].concat($2);
})
],
Elisions: [
o('Elision',
function() {
return [$1];
}),
o('Elisions Elision',
function() {
return $1.concat($2);
})
],
Elision: [
o(',',
function() {
return new Elision;
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Just simple, comma-separated, required arguments (no fancy syntax). We need
// this to be separate from the **ArgList** for use in **Switch** blocks, where
// having the newlines wouldn't make sense.
SimpleArgs: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Expression'),
o('ExpressionLine'),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('SimpleArgs , Expression',
function() {
return [].concat($1,
$3);
}),
o('SimpleArgs , ExpressionLine',
function() {
return [].concat($1,
$3);
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The variants of *try/catch/finally* exception handling blocks.
Try: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('TRY Block',
function() {
return new Try($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('TRY Block Catch',
function() {
return new Try($2,
$3[0],
$3[1]);
}),
o('TRY Block FINALLY Block',
function() {
return new Try($2,
null,
null,
$4);
}),
o('TRY Block Catch FINALLY Block',
function() {
return new Try($2,
$3[0],
$3[1],
$5);
})
],
// A catch clause names its error and runs a block of code.
Catch: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('CATCH Identifier Block',
function() {
return [$2,
$3];
}),
o('CATCH Object Block',
function() {
return [LOC(2)(new Value($2)),
$3];
}),
o('CATCH Block',
function() {
return [null,
$2];
})
],
// Throw an exception object.
Throw: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('THROW Expression',
function() {
return new Throw($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('THROW INDENT Object OUTDENT',
function() {
return new Throw(new Value($3));
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Parenthetical expressions. Note that the **Parenthetical** is a **Value**,
// not an **Expression**, so if you need to use an expression in a place
// where only values are accepted, wrapping it in parentheses will always do
// the trick.
Parenthetical: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('( Body )',
function() {
2010-10-07 03:53:26 +00:00
return new Parens($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('( INDENT Body OUTDENT )',
function() {
return new Parens($3);
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The condition portion of a while loop.
WhileLineSource: [
o('WHILE ExpressionLine',
function() {
return new While($2);
}),
o('WHILE ExpressionLine WHEN ExpressionLine',
function() {
return new While($2,
{
guard: $4
});
}),
o('UNTIL ExpressionLine',
function() {
return new While($2,
{
invert: true
});
}),
o('UNTIL ExpressionLine WHEN ExpressionLine',
function() {
return new While($2,
{
invert: true,
guard: $4
});
})
],
WhileSource: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('WHILE Expression',
function() {
return new While($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('WHILE Expression WHEN Expression',
function() {
return new While($2,
{
guard: $4
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('WHILE ExpressionLine WHEN Expression',
function() {
return new While($2,
{
guard: $4
});
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('UNTIL Expression',
function() {
return new While($2,
{
invert: true
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('UNTIL Expression WHEN Expression',
function() {
return new While($2,
{
invert: true,
guard: $4
});
}),
o('UNTIL ExpressionLine WHEN Expression',
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
function() {
return new While($2,
{
invert: true,
guard: $4
});
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The while loop can either be normal, with a block of expressions to execute,
// or postfix, with a single expression. There is no do..while.
While: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('WhileSource Block',
function() {
return $1.addBody($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('WhileLineSource Block',
function() {
return $1.addBody($2);
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Statement WhileSource',
function() {
return $2.addBody(LOC(1)(Block.wrap([$1])));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Expression WhileSource',
function() {
return $2.addBody(LOC(1)(Block.wrap([$1])));
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Loop',
function() {
return $1;
})
],
Loop: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('LOOP Block',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new While(LOC(1)(new BooleanLiteral('true'))).addBody($2);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('LOOP Expression',
function() {
Refactor `Literal` into several subtypes Previously, the parser created `Literal` nodes for many things. This resulted in information loss. Instead of being able to check the node type, we had to use regexes to tell the different types of `Literal`s apart. That was a bit like parsing literals twice: Once in the lexer, and once (or more) in the compiler. It also caused problems, such as `` `this` `` and `this` being indistinguishable (fixes #2009). Instead returning `new Literal` in the grammar, subtypes of it are now returned instead, such as `NumberLiteral`, `StringLiteral` and `IdentifierLiteral`. `new Literal` by itself is only used to represent code chunks that fit no category. (While mentioning `NumberLiteral`, there's also `InfinityLiteral` now, which is a subtype of `NumberLiteral`.) `StringWithInterpolations` has been added as a subtype of `Parens`, and `RegexWithInterpolations` as a subtype of `Call`. This makes it easier for other programs to make use of CoffeeScript's "AST" (nodes). For example, it is now possible to distinguish between `"a #{b} c"` and `"a " + b + " c"`. Fixes #4192. `SuperCall` has been added as a subtype of `Call`. Note, though, that some information is still lost, especially in the lexer. For example, there is no way to distinguish a heredoc from a regular string, or a heregex without interpolations from a regular regex. Binary and octal number literals are indistinguishable from hexadecimal literals. After the new subtypes were added, they were taken advantage of, removing most regexes in nodes.coffee. `SIMPLENUM` (which matches non-hex integers) had to be kept, though, because such numbers need special handling in JavaScript (for example in `1..toString()`). An especially nice hack to get rid of was using `new String()` for the token value for reserved identifiers (to be able to set a property on them which could survive through the parser). Now it's a good old regular string. In range literals, slices, splices and for loop steps when number literals are involved, CoffeeScript can do some optimizations, such as precomputing the value of, say, `5 - 3` (outputting `2` instead of `5 - 3` literally). As a side bonus, this now also works with hexadecimal number literals, such as `0x02`. Finally, this also improves the output of `coffee --nodes`: # Before: $ bin/coffee -ne 'while true "#{a}" break' Block While Value Bool Block Value Parens Block Op + Value """" Value Parens Block Value "a" "break" # After: $ bin/coffee -ne 'while true "#{a}" break' Block While Value BooleanLiteral: true Block Value StringWithInterpolations Block Op + Value StringLiteral: "" Value Parens Block Value IdentifierLiteral: a StatementLiteral: break
2016-01-31 19:24:31 +00:00
return new While(LOC(1)(new BooleanLiteral('true'))).addBody(LOC(2)(Block.wrap([$2])));
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Array, object, and range comprehensions, at the most generic level.
// Comprehensions can either be normal, with a block of expressions to execute,
// or postfix, with a single expression.
For: [
o('Statement ForBody',
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
function() {
return $2.addBody($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Expression ForBody',
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
function() {
return $2.addBody($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ForBody Block',
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
function() {
return $1.addBody($2);
}),
o('ForLineBody Block',
function() {
return $1.addBody($2);
2010-11-20 21:25:22 +00:00
})
],
ForBody: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('FOR Range',
function() {
return new For([],
{
2013-02-28 13:37:30 +00:00
source: LOC(2)(new Value($2))
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FOR Range BY Expression',
function() {
return new For([],
{
source: LOC(2)(new Value($2)),
step: $4
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ForStart ForSource',
function() {
return $1.addSource($2);
2010-11-20 21:25:22 +00:00
})
],
ForLineBody: [
o('FOR Range BY ExpressionLine',
function() {
return new For([],
{
source: LOC(2)(new Value($2)),
step: $4
});
}),
o('ForStart ForLineSource',
function() {
return $1.addSource($2);
})
],
2010-11-20 21:25:22 +00:00
ForStart: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('FOR ForVariables',
function() {
return new For([],
{
name: $2[0],
index: $2[1]
});
}),
o('FOR AWAIT ForVariables',
function() {
var index,
name;
[name,
index] = $3;
return new For([],
{
name,
index,
await: true,
awaitTag: LOC(2)(new Literal($2))
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FOR OWN ForVariables',
function() {
var index,
name;
[name,
index] = $3;
return new For([],
{
name,
index,
own: true,
ownTag: LOC(2)(new Literal($2))
});
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// An array of all accepted values for a variable inside the loop.
// This enables support for pattern matching.
ForValue: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Identifier'),
o('ThisProperty'),
o('Array',
function() {
2013-02-28 13:37:30 +00:00
return new Value($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Object',
function() {
2013-02-28 13:37:30 +00:00
return new Value($1);
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// An array or range comprehension has variables for the current element
// and (optional) reference to the current index. Or, *key, value*, in the case
// of object comprehensions.
2010-11-20 21:25:22 +00:00
ForVariables: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('ForValue',
function() {
2010-11-20 21:25:22 +00:00
return [$1];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('ForValue , ForValue',
function() {
return [$1,
$3];
2010-11-20 21:25:22 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The source of a comprehension is an array or object with an optional guard
// clause. If it's an array comprehension, you can also choose to step through
// in fixed-size increments.
2010-11-20 21:25:22 +00:00
ForSource: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('FORIN Expression',
function() {
2010-02-11 04:24:05 +00:00
return {
source: $2
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FOROF Expression',
function() {
2010-02-11 04:24:05 +00:00
return {
source: $2,
2010-11-20 21:25:22 +00:00
object: true
2010-02-11 04:24:05 +00:00
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FORIN Expression WHEN Expression',
function() {
return {
source: $2,
2010-11-20 21:25:22 +00:00
guard: $4
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FORIN ExpressionLine WHEN Expression',
function() {
return {
source: $2,
guard: $4
};
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('FOROF Expression WHEN Expression',
function() {
return {
source: $2,
2010-11-20 21:25:22 +00:00
guard: $4,
object: true
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FOROF ExpressionLine WHEN Expression',
function() {
return {
source: $2,
guard: $4,
object: true
};
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('FORIN Expression BY Expression',
function() {
return {
2010-11-20 21:25:22 +00:00
source: $2,
step: $4
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FORIN ExpressionLine BY Expression',
function() {
return {
source: $2,
step: $4
};
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('FORIN Expression WHEN Expression BY Expression',
function() {
return {
2010-11-20 21:25:22 +00:00
source: $2,
guard: $4,
step: $6
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FORIN ExpressionLine WHEN Expression BY Expression',
function() {
return {
source: $2,
guard: $4,
step: $6
};
}),
o('FORIN Expression WHEN ExpressionLine BY Expression',
function() {
return {
source: $2,
guard: $4,
step: $6
};
}),
o('FORIN ExpressionLine WHEN ExpressionLine BY Expression',
function() {
return {
source: $2,
guard: $4,
step: $6
};
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('FORIN Expression BY Expression WHEN Expression',
function() {
return {
2010-11-20 21:25:22 +00:00
source: $2,
step: $4,
guard: $6
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FORIN ExpressionLine BY Expression WHEN Expression',
function() {
return {
source: $2,
step: $4,
guard: $6
};
}),
o('FORIN Expression BY ExpressionLine WHEN Expression',
function() {
return {
source: $2,
step: $4,
guard: $6
};
}),
o('FORIN ExpressionLine BY ExpressionLine WHEN Expression',
function() {
return {
source: $2,
step: $4,
guard: $6
};
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('FORFROM Expression',
function() {
return {
source: $2,
from: true
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('FORFROM Expression WHEN Expression',
function() {
return {
source: $2,
guard: $4,
from: true
};
}),
o('FORFROM ExpressionLine WHEN Expression',
function() {
return {
source: $2,
guard: $4,
from: true
};
})
],
ForLineSource: [
o('FORIN ExpressionLine',
function() {
return {
source: $2
};
}),
o('FOROF ExpressionLine',
function() {
return {
source: $2,
object: true
};
}),
o('FORIN Expression WHEN ExpressionLine',
function() {
return {
source: $2,
guard: $4
};
}),
o('FORIN ExpressionLine WHEN ExpressionLine',
function() {
return {
source: $2,
guard: $4
};
}),
o('FOROF Expression WHEN ExpressionLine',
function() {
return {
source: $2,
guard: $4,
object: true
};
}),
o('FOROF ExpressionLine WHEN ExpressionLine',
function() {
return {
source: $2,
guard: $4,
object: true
};
}),
o('FORIN Expression BY ExpressionLine',
function() {
return {
source: $2,
step: $4
};
}),
o('FORIN ExpressionLine BY ExpressionLine',
function() {
return {
source: $2,
step: $4
};
}),
o('FORIN Expression WHEN Expression BY ExpressionLine',
function() {
return {
source: $2,
guard: $4,
step: $6
};
}),
o('FORIN ExpressionLine WHEN Expression BY ExpressionLine',
function() {
return {
source: $2,
guard: $4,
step: $6
};
}),
o('FORIN Expression WHEN ExpressionLine BY ExpressionLine',
function() {
return {
source: $2,
guard: $4,
step: $6
};
}),
o('FORIN ExpressionLine WHEN ExpressionLine BY ExpressionLine',
function() {
return {
source: $2,
guard: $4,
step: $6
};
}),
o('FORIN Expression BY Expression WHEN ExpressionLine',
function() {
return {
source: $2,
step: $4,
guard: $6
};
}),
o('FORIN ExpressionLine BY Expression WHEN ExpressionLine',
function() {
return {
source: $2,
step: $4,
guard: $6
};
}),
o('FORIN Expression BY ExpressionLine WHEN ExpressionLine',
function() {
return {
source: $2,
step: $4,
guard: $6
};
}),
o('FORIN ExpressionLine BY ExpressionLine WHEN ExpressionLine',
function() {
return {
source: $2,
step: $4,
guard: $6
};
}),
o('FORFROM ExpressionLine',
function() {
return {
source: $2,
from: true
};
}),
o('FORFROM Expression WHEN ExpressionLine',
function() {
return {
source: $2,
guard: $4,
from: true
};
}),
o('FORFROM ExpressionLine WHEN ExpressionLine',
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
function() {
return {
source: $2,
guard: $4,
from: true
};
2010-02-11 04:24:05 +00:00
})
],
Switch: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('SWITCH Expression INDENT Whens OUTDENT',
function() {
return new Switch($2,
$4);
}),
o('SWITCH ExpressionLine INDENT Whens OUTDENT',
function() {
return new Switch($2,
$4);
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('SWITCH Expression INDENT Whens ELSE Block OUTDENT',
function() {
return new Switch($2,
$4,
$6);
}),
o('SWITCH ExpressionLine INDENT Whens ELSE Block OUTDENT',
function() {
return new Switch($2,
$4,
$6);
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('SWITCH INDENT Whens OUTDENT',
function() {
return new Switch(null,
$3);
}),
o('SWITCH INDENT Whens ELSE Block OUTDENT',
function() {
return new Switch(null,
$3,
$5);
2010-02-11 04:24:05 +00:00
})
],
Whens: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('When'),
o('Whens When',
function() {
return $1.concat($2);
2010-02-11 04:24:05 +00:00
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// An individual **When** clause, with action.
When: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('LEADING_WHEN SimpleArgs Block',
function() {
return [[$2,
$3]];
}),
o('LEADING_WHEN SimpleArgs Block TERMINATOR',
function() {
return [[$2,
$3]];
})
],
// The most basic form of *if* is a condition and an action. The following
// if-related rules are broken up along these lines in order to avoid
// ambiguity.
IfBlock: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('IF Expression Block',
function() {
return new If($2,
$3,
{
type: $1
2010-04-27 23:35:15 +00:00
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('IfBlock ELSE IF Expression Block',
function() {
return $1.addElse(LOC(3,
5)(new If($4,
$5,
{
type: $3
})));
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// The full complement of *if* expressions, including postfix one-liner
// *if* and *unless*.
If: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('IfBlock'),
o('IfBlock ELSE Block',
function() {
2011-01-11 04:19:31 +00:00
return $1.addElse($3);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Statement POST_IF Expression',
function() {
return new If($3,
LOC(1)(Block.wrap([$1])),
{
type: $2,
2010-04-05 14:26:23 +00:00
statement: true
});
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Expression POST_IF Expression',
function() {
return new If($3,
LOC(1)(Block.wrap([$1])),
{
type: $2,
2010-02-11 04:24:05 +00:00
statement: true
});
})
],
IfBlockLine: [
o('IF ExpressionLine Block',
function() {
return new If($2,
$3,
{
type: $1
});
}),
o('IfBlockLine ELSE IF ExpressionLine Block',
function() {
return $1.addElse(LOC(3,
5)(new If($4,
$5,
{
type: $3
})));
})
],
IfLine: [
o('IfBlockLine'),
o('IfBlockLine ELSE Block',
function() {
return $1.addElse($3);
}),
o('Statement POST_IF ExpressionLine',
function() {
return new If($3,
LOC(1)(Block.wrap([$1])),
{
type: $2,
statement: true
});
}),
o('Expression POST_IF ExpressionLine',
function() {
return new If($3,
LOC(1)(Block.wrap([$1])),
{
type: $2,
statement: true
});
})
],
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Arithmetic and logical operators, working on one or more operands.
// Here they are grouped by order of precedence. The actual precedence rules
// are defined at the bottom of the page. It would be shorter if we could
// combine most of these rules into a single generic *Operand OpSymbol Operand*
// -type rule, but in order to make the precedence binding possible, separate
// rules are necessary.
OperationLine: [
o('UNARY ExpressionLine',
function() {
return new Op($1,
$2);
})
],
Operation: [
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('UNARY Expression',
function() {
return new Op($1,
$2);
}),
o('UNARY_MATH Expression',
function() {
return new Op($1,
$2);
}),
o('- Expression',
(function() {
return new Op('-',
$2);
}),
{
prec: 'UNARY_MATH'
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('+ Expression',
(function() {
return new Op('+',
$2);
}),
{
prec: 'UNARY_MATH'
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('AWAIT Expression',
function() {
return new Op($1,
$2);
}),
o('AWAIT INDENT Object OUTDENT',
function() {
return new Op($1,
$3);
}),
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('-- SimpleAssignable',
function() {
return new Op('--',
$2);
}),
o('++ SimpleAssignable',
function() {
return new Op('++',
$2);
}),
o('SimpleAssignable --',
function() {
return new Op('--',
$1,
null,
true);
}),
o('SimpleAssignable ++',
function() {
return new Op('++',
$1,
null,
true);
}),
// [The existential operator](https://coffeescript.org/#existential-operator).
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
o('Expression ?',
function() {
return new Existence($1);
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('Expression + Expression',
function() {
return new Op('+',
$1,
$3);
}),
o('Expression - Expression',
function() {
return new Op('-',
$1,
$3);
}),
o('Expression MATH Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression ** Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression SHIFT Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression COMPARE Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression & Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression ^ Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression | Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression && Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression || Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression BIN? Expression',
function() {
return new Op($2,
$1,
$3);
}),
o('Expression RELATION Expression',
function() {
if ($2.charAt(0) === '!') {
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
return new Op($2.slice(1),
$1,
$3).invert();
} else {
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
return new Op($2,
$1,
$3);
}
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
}),
o('SimpleAssignable COMPOUND_ASSIGN Expression',
function() {
return new Assign($1,
$3,
$2);
}),
o('SimpleAssignable COMPOUND_ASSIGN INDENT Expression OUTDENT',
function() {
return new Assign($1,
$4,
$2);
}),
o('SimpleAssignable COMPOUND_ASSIGN TERMINATOR Expression',
function() {
return new Assign($1,
$4,
$2);
})
2010-02-11 04:24:05 +00:00
]
};
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Precedence
// ----------
// Operators at the top of this list have higher precedence than the ones lower
// down. Following these rules is what makes `2 + 3 * 4` parse as:
// 2 + (3 * 4)
// And not:
// (2 + 3) * 4
operators = [['left', '.', '?.', '::', '?::'], ['left', 'CALL_START', 'CALL_END'], ['nonassoc', '++', '--'], ['left', '?'], ['right', 'UNARY'], ['right', 'AWAIT'], ['right', '**'], ['right', 'UNARY_MATH'], ['left', 'MATH'], ['left', '+', '-'], ['left', 'SHIFT'], ['left', 'RELATION'], ['left', 'COMPARE'], ['left', '&'], ['left', '^'], ['left', '|'], ['left', '&&'], ['left', '||'], ['left', 'BIN?'], ['nonassoc', 'INDENT', 'OUTDENT'], ['right', 'YIELD'], ['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN', 'THROW', 'EXTENDS'], ['right', 'FORIN', 'FOROF', 'FORFROM', 'BY', 'WHEN'], ['right', 'IF', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'IMPORT', 'EXPORT', 'DYNAMIC_IMPORT'], ['left', 'POST_IF']];
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Wrapping Up
// -----------
// Finally, now that we have our **grammar** and our **operators**, we can create
// our **Jison.Parser**. We do this by processing all of our rules, recording all
// terminals (every symbol which does not appear as the name of a rule above)
// as "tokens".
2010-02-11 04:24:05 +00:00
tokens = [];
2010-10-01 22:26:37 +00:00
for (name in grammar) {
alternatives = grammar[name];
2010-12-23 18:50:52 +00:00
grammar[name] = (function() {
var i, j, len, len1, ref, results;
results = [];
for (i = 0, len = alternatives.length; i < len; i++) {
alt = alternatives[i];
ref = alt[0].split(' ');
for (j = 0, len1 = ref.length; j < len1; j++) {
token = ref[j];
2012-04-10 18:57:45 +00:00
if (!grammar[token]) {
tokens.push(token);
}
}
if (name === 'Root') {
alt[1] = `return ${alt[1]}`;
}
results.push(alt);
}
return results;
2010-12-23 18:50:52 +00:00
})();
}
[CS2] Comments (#4572) * Make `addLocationDataFn` more DRY * Style fixes * Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data * Fix style. * Fix style. * Label test comments * Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing * New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out). * If a comment follows a class declaration, move the comment inside the class body * Style * Improve indentation of multiline comments * Fix indentation for block comments, at least in the cases covered by the one failing test * Don’t reverse the order of unshifted comments * Simplify rewriter’s handling of comments, generalizing the special case * Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through * Improve comments; fix multiline flag * Prepare HereComments for processing line comments * Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit * Updated compiler, now with line comments * `process` doesn’t exist in the browser, so we should check for its existence first * Update parser output * Test that proves #4290 is fixed * Indent line comments, first pass * Compiled output with indented line comments * Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline * Revised output * Cleanup * Split “multiline” line comment tokens, shifting them forward or back as appropriate * Fix comments in module specifiers * Abstract attaching comments to a node * Line comments in interpolated strings * Line comments can’t be multiline anymore * Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail) * Make comments compilation more object-oriented * Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment * Improve eqJS helper * Fix #4290 definitively, with improved output for arrays with interspersed block comments * Add support for line comments output interspersed within arrays * Fix mistake, don’t lose the variable we’re working on * Remove redundant replacements * Check for indentation only from the start of the string * Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces * Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset * Don’t rely on `fragment.type`, which can break when the compiler is minified * Updated generated docs and browser compiler * Output block comments after function arguments * Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output * Create new FuncGlyph node, to hold comments we want to output near the function parameters * Block comments between `)` and `->`/`=>` get output between `)` and `{`. * Fix indentation of comments that are the first line inside a bare mode block * Updated output * Full Flow example * Updated browser compiler * Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return` * Abstract token insertion code * Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node * Allow `SUPER` tokens to carry comments * Rescue comments from `Existence` nodes and `If` nodes’ conditions * Rescue comments after `\` line continuation tokens * Updated compiled output * Updated browser compiler * Output block comments in the same `compileFragments` method as line comments, except for inline block comments * Comments before splice * Updated browser compiler * Track compiledComments as a property of Base, to ensure that it’s not a global variable * Docs: split up the Usage section * Docs for type annotations via Flow; updated docs output * Update regular comments documentation * Updated browser compiler * Comments before soak * Comments before static methods, and probably before `@variable =` (this) assignments generally * Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods * Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call * Fix missing comments before `if not` (i.e. before a UNARY token) * Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit) * Comments within heregexes * Updated browser compiler * Update description to reflect what’s now happening in compileCommentFragments * Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace * Better future-proof comments tests * Comments before object destructuring; abstract method for setting comments aside before compilation * Handle more cases of comments before or after `for` loop declaration lines * Fix indentation of comments preceding `for` loops * Fix comment before splat function parameter * Catch another RegexWithInterpolations comment edge case * Updated browser compiler * Change heregex example to one that’s more readable; update output * Remove a few last references to the defunct HERECOMMENT token * Abstract location hash creation into a function * Improved clarity per code review notes * Updated browser compiler
2017-08-03 02:34:34 +00:00
// Initialize the **Parser** with our list of terminal **tokens**, our **grammar**
// rules, and the name of the root. Reverse the operators because Jison orders
// precedence from low to high, and we have it high to low
// (as in [Yacc](http://dinosaur.compilertools.net/yacc/index.html)).
2010-02-16 06:04:48 +00:00
exports.parser = new Parser({
tokens: tokens.join(' '),
bnf: grammar,
operators: operators.reverse(),
2010-02-11 04:24:05 +00:00
startSymbol: 'Root'
});
2011-12-14 15:39:20 +00:00
}).call(this);