Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Spread operator #9

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
557e531
spread operators in arrays
fdecampredon Mar 25, 2014
5d4165d
spread operator in call expression
fdecampredon Mar 25, 2014
eea0233
renaming
fdecampredon Mar 25, 2014
f624afa
spread in new expression
fdecampredon Mar 25, 2014
4f31127
cleaning and line break respect in new expression
fdecampredon Mar 25, 2014
a2491ef
replace spread template
fdecampredon Mar 25, 2014
366b3f4
comment with examples of how the spread operator works
fdecampredon Mar 25, 2014
b90ed59
todo comments syntax correction
fdecampredon Mar 25, 2014
7366326
externalize templates in a separate modules
fdecampredon Mar 26, 2014
7d7aeac
fix case of '(' and ')' in comments that was replaced
fdecampredon Mar 26, 2014
7828a12
Fix new expression with function that returns value
fdecampredon Mar 26, 2014
70bafa2
Revert templates extenalizing
fdecampredon Mar 27, 2014
ab7c4b4
reformat a little the code source output in tests
fdecampredon Mar 27, 2014
5d4d437
add runtimes inclusion logic
fdecampredon Mar 28, 2014
8615906
fix bad tests
fdecampredon Mar 28, 2014
0aa0ecb
replace spread element check by runtimes call
fdecampredon Mar 28, 2014
f15ee21
replace iife by runtimes call to executeNewExpression
fdecampredon Apr 1, 2014
1022d74
Merge branch 'spread-operator-with-runtime' into spread-operator
fdecampredon Apr 2, 2014
2f16f3d
remove loging
fdecampredon Apr 2, 2014
0e94da6
adding failing test case for array elements without spread operator
fdecampredon Apr 2, 2014
c941ee0
fix output code source too match the excepted transformation
fdecampredon Apr 2, 2014
d12fc1b
remove jshint comments in spread-operator-runtime
fdecampredon Apr 2, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
todo comments syntax correction
  • Loading branch information
fdecampredon committed Mar 25, 2014
commit b90ed592550847bed792685f5deda51870762676
8 changes: 4 additions & 4 deletions visitors/es6-spread-operator-visitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ function visitFunctionCallWithSpreadElement(traverse, node, path, state) {
utils.append('.apply(undefined, Array.prototype.concat.apply([],', state);
}
utils.catchup(node.arguments[0].range[0], state, function (content) {
//todo too much simplist here we will replace all '(' in comments also
// TODO: too much simplist here we will replace all '(' in comments also
return content.replace(/\(/g, '[');
});
insertElementsWithSpread(node.arguments, state);
utils.catchup(node.range[1], state, function (content) {
//todo too much simplist here we will replace all ')' in comments also
// TODO: too much simplist here we will replace all ')' in comments also
return content.replace(/\)/g, ']');
});
utils.append('))', state);
Expand All @@ -124,12 +124,12 @@ function visitNewExpressionWithSpreadElement(traverse, node, path, state) {
utils.append(', ' + resultIdent + ' = Object.create(' + classIdent + '.prototype);', state);
utils.append( classIdent + '.apply('+ resultIdent + ', Array.prototype.concat.apply([],', state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically you need to examine the result of ClassIdent.apply(...) in case it returns an object, and (if so) replace resultIdent with that new value. I realize this is kind of pedantic, but I mention it as another argument in favor of handling logic like this inside some kind of runtime abstraction, rather than generating code that checks this case every time a ... operator is used.

utils.catchup(node.arguments[0].range[0], state, function (content) {
//todo too much simplist here we will replace all '(' in comments also
// TODO: too much simplist here we will replace all '(' in comments also
return content.replace(/\(/g, '[');
});
insertElementsWithSpread(node.arguments, state);
utils.catchup(node.range[1], state, function (content) {
//todo too much simplist here we will replace all ')' in comments also
// TODO: too much simplist here we will replace all ')' in comments also
return content.replace(/\)/g, ']');
});
utils.append('));return ' + resultIdent + ';})()', state);
Expand Down