Commit Graph

28 Commits

Author SHA1 Message Date
Geoffrey Booth df9d4a2343 [CS2] 2.0.0-beta5 (#4682)
* Upgrade docs to Bootstrap 4 beta, including refactoring styles; upgrade docs jQuery and CodeMirror

* Better style the docs for mobile, including Try CoffeeScript

* Fix #4642, erroneous statement about named functions

* Update packages

* 2.0.0-beta5
2017-09-02 12:48:38 -07:00
Geoffrey Booth 4a4f752204 Fix #3098: Suppressed newline should be unsuppressed by semicolon (#4669) 2017-09-01 07:09:36 -07:00
Geoffrey Booth 906bedf93a Fix #1768: Ignore space after `::` (#4670) 2017-08-30 22:43:17 -07:00
Geoffrey Booth c81e2d4767 Fix #4575: Check for the previous token’s existence before comparing against it (#4663) 2017-08-24 00:05:26 -07:00
Geoffrey Booth 40c351135a [CS2] Fix #4629: interpolations (whether in strings or CSX tags) with only comments (#4659)
* Fix #4629: interpolations (whether in strings or CSX tags) that contain nothing but comments should not be optimized out

* Template literals need an expression inside their interpolations, so if we only have a comment to put in there, toss in an empty string as well
2017-08-23 23:34:59 -07:00
Geoffrey Booth ae7f97b639 2.0.0-beta4 (#4628)
* 2.0.0-beta4 changelog

* Recompile parser, update browser compiler

* Updated annotated source and browser tests

* Bump version to 2.0.0-beta4
2017-08-03 18:11:19 -07:00
zdenko cbf035fca9 [CS2] CSX spread attributes: <div {props…} /> (#4607)
* CSX spread attributes: <div {props...} />

* whitespace cleanup

* Style

* valid CSX attributes

* added comments; cleanup

* Fixed allowed CSX properties.

* Cleanup

* Typo

* Improved RegEx

* Reworked CSX attributes

* small fix for CSX attribute validation

* cleanup

* tests

* fix nested assignement; remove unused variable

* cleanup; improve tests

* fix esoteric case; improve tracking nested splats in CSX tag
2017-08-02 21:00:39 -07:00
zdenko a118ec7cc9 [CS2] fix for “`do super` in constructor” bug (#4627)
* bug fix 'do super' in constructor

* improve regex
2017-08-02 19:41:01 -07:00
Geoffrey Booth 6d21dc5495 [CS2] Comments (#4572)
* Make `addLocationDataFn` more DRY

* Style fixes

* Provide access to full parser inside our custom function running in parser.js; rename the function to lay the groundwork for adding data aside from location data

* Fix style.

* Fix style.

* Label test comments

* Update grammar to remove comment tokens; update DSL to call new helper function that preserves comments through parsing

* New implementation of compiling block comments: the lexer pulls them out of the token stream, attaching them as a property to a token; the rewriter moves the attachment around so it lives on a token that is destined to make it through to compilation (and in a good placement); and the nodes render the block comment. All tests but one pass (commented out).

* If a comment follows a class declaration, move the comment inside the class body

* Style

* Improve indentation of multiline comments

* Fix indentation for block comments, at least in the cases covered by the one failing test

* Don’t reverse the order of unshifted comments

* Simplify rewriter’s handling of comments, generalizing the special case

* Expand the list of tokens we need to avoid for passing comments through the parser; get some literal tokens to have nodes created for them so that the comments pass through

* Improve comments; fix multiline flag

* Prepare HereComments for processing line comments

* Line comments, first draft: the tests pass, but the line comments aren’t indented and sometimes trail previous lines when they shouldn’t; updated compiler output in following commit

* Updated compiler, now with line comments

* `process` doesn’t exist in the browser, so we should check for its existence first

* Update parser output

* Test that proves #4290 is fixed

* Indent line comments, first pass

* Compiled output with indented line comments

* Comments that start a new line shouldn’t trail; don’t skip comments attached to generated tokens; stop looking for indentation once we hit a newline

* Revised output

* Cleanup

* Split “multiline” line comment tokens, shifting them forward or back as appropriate

* Fix comments in module specifiers

* Abstract attaching comments to a node

* Line comments in interpolated strings

* Line comments can’t be multiline anymore

* Improve handling of blank lines and indentation of following comments that start a new line (i.e. don’t trail)

* Make comments compilation more object-oriented

* Remove lots of dead code that we don’t need anymore because a comment is never a node, only a fragment

* Improve eqJS helper

* Fix #4290 definitively, with improved output for arrays with interspersed block comments

* Add support for line comments output interspersed within arrays

* Fix mistake, don’t lose the variable we’re working on

* Remove redundant replacements

* Check for indentation only from the start of the string

* Indentations in generated JS are always multiples of two spaces (never tabs) so just look for 2+ spaces

* Update package versions; run Babel twice, once for each preset, temporarily until a Babili bug is fixed that prevents it from running with the env preset

* Don’t rely on `fragment.type`, which can break when the compiler is minified

* Updated generated docs and browser compiler

* Output block comments after function arguments

* Comments appear above scope `var` declarations; better tracking of generated `JS` tokens created only to shepherd comments through to the output

* Create new FuncGlyph node, to hold comments we want to output near the function parameters

* Block comments between `)` and `->`/`=>` get output between `)` and `{`.

* Fix indentation of comments that are the first line inside a bare mode block

* Updated output

* Full Flow example

* Updated browser compiler

* Abstract and organize comment fragment generation code; store more properties on the comment fragment objects; make `throw` behave like `return`

* Abstract token insertion code

* Add missing locationData to STRING_START token, giving it the locationData of the overall StringWithInterpolations token so that comments attached to STRING_START end up on the StringWithInterpolations node

* Allow `SUPER` tokens to carry comments

* Rescue comments from `Existence` nodes and `If` nodes’ conditions

* Rescue comments after `\` line continuation tokens

* Updated compiled output

* Updated browser compiler

* Output block comments in the same `compileFragments` method as line comments, except for inline block comments

* Comments before splice

* Updated browser compiler

* Track compiledComments as a property of Base, to ensure that it’s not a global variable

* Docs: split up the Usage section

* Docs for type annotations via Flow; updated docs output

* Update regular comments documentation

* Updated browser compiler

* Comments before soak

* Comments before static methods, and probably before `@variable =` (this) assignments generally

* Comments before ‘if exists?’, refactor comment before ‘if this.var’ to be more precise, improve helper methods

* Comments before a method that contains ‘super()’ should output above the method property, not above the ‘super.method()’ call

* Fix missing comments before `if not` (i.e. before a UNARY token)

* Fix comments before ‘for’; add test for comment before assignment if (fixed in earlier commit)

* Comments within heregexes

* Updated browser compiler

* Update description to reflect what’s now happening in compileCommentFragments

* Preserve blank lines between line comments; output “whitespace-only” line comments as blank lines, rather than `//` following by whitespace

* Better future-proof comments tests

* Comments before object destructuring; abstract method for setting comments aside before compilation

* Handle more cases of comments before or after `for` loop declaration lines

* Fix indentation of comments preceding `for` loops

* Fix comment before splat function parameter

* Catch another RegexWithInterpolations comment edge case

* Updated browser compiler

* Change heregex example to one that’s more readable; update output

* Remove a few last references to the defunct HERECOMMENT token

* Abstract location hash creation into a function

* Improved clarity per code review notes

* Updated browser compiler
2017-08-02 19:34:34 -07:00
Julian Rosse 50674cb351 [CS2] Fix #3199: throw multiline implicit object (#4599)
* throw multiline implicit object [Fixes #3199]

* restrict to Object

* test error on non-object

* test error on call indented non-object
2017-07-09 10:28:50 -07:00
Geoffrey Booth 704924c3cd 2.0.0-beta3 (#4594)
* 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

* Fix docs scroll position getting screwed up by CodeMirror initialization

* Breaking change documentation about => (fixes #4593)

* Spread/rest syntax documentation

* Documentation about bound class methods

* 2.0.0-beta3 changelog

* Add note about ‘lib’

* Fix accidentally converting this to tabs

* Bump version to 2.0.0-beta3

* Update annotated source and test.html
2017-06-30 09:58:05 -07:00
Julian Rosse b1d2061cbc [CS2] Fix #3906: handle indentation inside indented chain (#4587)
* safe missing end token error [Fixes #3906]

* handle indentation inside indented chain [Fixes #3906]
2017-06-29 18:39:05 -07:00
Michal Srb dc0fb85fd3 [CS2] Support for CSX - equivalent of JSX (#4551)
* CSX implementation

* fixed comment, used toJS, added error tests, fixed error in identifier regex, fixed interpolation inside attributes value and added test

* added missing test for bare attributes, split attribute and indentifier regex, fixed checking for closing tags closing angle bracket

* Refactor tests that compare expected generated JavaScript with actual generated JavaScript to use common helper; add colors to error message to make differences easier to read

* Better match the style of the rest of the codebase

* Remove unused function

* More style fixes

* Allow unspaced less-than operator when not using CSX

* Replace includesCSX with a counter and simplify the unspaced operator logic

* Fixed indexing and realized that I completely enabled the tight spacing, added a test for it too

* Style fixes
2017-06-06 23:33:46 -07:00
Julian Rosse 63b109a4f5 Fix #4544: postfix conditional on first line of implicit object (#4554)
* support postfix conditional on first line of implicit object

* cleanup cleanup

* also fixes #2051, added test
2017-05-29 17:29:45 -07:00
Geoffrey Booth d756bd6851 [CS2] 2.0.0-beta2 (#4550)
* Breaking changes note about bound class methods

* Changelog for 2.0.0-beta2, including renaming “Change Log” to “Changelog” (the preferred spelling per Wikipedia)

* Update version to 2.0.0-beta2

* 2.0.0-beta2 generated output
2017-05-16 11:53:22 -07:00
Geoffrey Booth 2f9ab1d328 [CS2] `return` and `export default` can now accept implicit objects (#4532)
* Start with the test I want to pass: return an implicit (braces-less) object

* Update Rewriter class to follow pattern of nodes.coffee; move debugging snippet to where it’ll work in CS2

* Allow export default implicit object

* `return` assumes a continuation onto the next line *if* the next line is indented

* Fix comment; improve test
2017-05-01 19:26:24 -07:00
Julian Rosse 7ef5cb4a1f Keep unicode code point escapes as is when possible (#4520) 2017-04-25 19:15:08 +02:00
Geoffrey Booth 07ae1edb44 [CS2] Remove unnecessary utility helper functions (#4526)
* Uncomment module test that was waiting for classes to be supported

* Rely on native indexOf

* Replace `bind` helper with native `bind` (no shortcut necessary)

* Update output

* Update modules class tests

* Remove helper for prototype extends

* Update docs to reflect removed extends operator

* Add shortcut for splice, like we have for slice
2017-04-25 07:10:42 -07:00
Geoffrey Booth 5651b8b14b [CS2] Fix non-bare `get` `set` when called with `@` argument (#4525)
* Fixes #4524: `get` and `set` should be usable without parentheses when accessed via a period

* More get/set tests
2017-04-23 11:23:36 -07:00
Julian Rosse 89db842c3d merge master 2017-04-20 14:41:28 -05:00
Geoffrey Booth db216ec384 [CS2] 2.0.0-beta1 (#4499)
* Fix browser build to incorporate Markdown-It, not Marked

* Update Google Closure Compiler; recompile browser build but with MINIFY=false, because Closure Compiler throws an error on our current code; see https://github.com/google/closure-compiler-js/issues/59

* Bump version to 2.0.0-beta1; do release build, with updated docs and annotated source
2017-04-13 10:42:32 -07:00
Geoffrey Booth 9b77371ea8 Merge commit '72cf485dceb6a88abb3b83493032734409c3591a' into 2
# Conflicts:
#	Cakefile
#	docs/v1/index.html
#	documentation/sections/changelog.md
#	documentation/sections/installation.md
#	documentation/sections/introduction.md
#	lib/coffee-script/nodes.js
#	lib/coffee-script/rewriter.js
#	lib/coffee-script/sourcemap.js
#	lib/coffeescript/browser.js
#	lib/coffeescript/cake.js
#	lib/coffeescript/coffeescript.js
#	lib/coffeescript/command.js
#	lib/coffeescript/grammar.js
#	lib/coffeescript/helpers.js
#	lib/coffeescript/index.js
#	lib/coffeescript/lexer.js
#	lib/coffeescript/optparse.js
#	lib/coffeescript/register.js
#	lib/coffeescript/repl.js
#	lib/coffeescript/scope.js
#	package.json
2017-04-12 20:27:57 -07:00
Geoffrey Booth 8292d25d29 [CS2] Throw an error for ambiguous `get` or `set` keywords or function calls (#4484)
* Throw an error for ambiguous `get` or `set` function calls or ES5 getter/setter keywords, to warn the user to use parentheses if they intend a function call (or to inform them that `get` or `set` cannot be used as a keyword)

* Code golf

* Catch get or set keyword before static method

* DRY up getting the previous token

* Throw an error if get or set are used as keywords before what looks like a function or method with an interpolated/dynamic name

* Allow `get` or `set` parentheses-less function calls when first argument is a string without a colon (so a plain string, not a property accessor)

* Revert "Allow `get` or `set` parentheses-less function calls when first argument is a string without a colon (so a plain string, not a property accessor)"

This reverts commit 2d1addf5a4.

* Optimization

* No longer throw an error on `get` or `set` function calls to objects with dynamic property names (introduces a way to circumvent our check for trying to avoid the `get` or `set` keywords, but not worth the complications for this tiny edge case)
2017-04-08 21:59:09 -07:00
Julian Rosse 76945ab458 Fix #4487: Outdentation bug (#4488) 2017-04-08 13:12:55 -07:00
Geoffrey Booth b192e215a5 [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 10:06:45 -07:00
Geoffrey Booth cfdec64958 Merge branch 'master' of github.com:jashkenas/coffeescript into 2
# Conflicts:
#	lib/coffee-script/parser.js
#	lib/coffeescript/lexer.js
2017-04-02 23:10:31 -07:00
Geoffrey Booth 221a8720fe Merge branch '2' into 2.0.0-alpha1
# Conflicts:
#	Cakefile
#	README.md
#	documentation/sections/changelog.md
2017-02-18 18:36:15 -05:00
Geoffrey 4cc701a9da Remove hyphen in `coffee-script` 2017-02-12 17:00:05 -08:00