Skip to content

Commit

Permalink
Merge branch 'feature/spread-loop' into prerelease/3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 8, 2017
2 parents e7a0f21 + cb3f582 commit ee270bf
Show file tree
Hide file tree
Showing 131 changed files with 342 additions and 592 deletions.
3 changes: 1 addition & 2 deletions src/config.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export getParserOpts(pluginOpts, initialParserOpts) ->
"objectRestSpread", "asyncFunctions", "asyncGenerators"
"classProperties", "classConstructorCall", "decorators"
"dynamicImport", "doExpressions", "seqExprRequiresParen"
"noLabeledExpressionStatements"
"noLabeledExpressionStatements", "spreadLoop"
)

if pluginOpts?.whiteblock:
Expand All @@ -116,7 +116,6 @@ export getParserOpts(pluginOpts, initialParserOpts) ->
if pluginOpts?.bangCall != false: plugins.push("bangCall")
if not pluginOpts?.noEnforcedSubscriptIndentation: plugins.push("enforceSubscriptIndentation")
if pluginOpts?.flippedImports: plugins.push("flippedImports")
if pluginOpts?.enhancedComprehension != false: plugins.push("splatComprehension")
if pluginOpts?.placeholderArgs: plugins.push("syntacticPlaceholder")
if pluginOpts?.placeholder:
parserOpts.placeholder = pluginOpts.placeholder
Expand Down
19 changes: 9 additions & 10 deletions src/index.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { preParseInitialization } from './config'
import findBabelOptionsForPlugin from './util/findBabelOptionsForPlugin'
import { createCompilerState, preCompileInitialization, postprocess } from './state/compilerState'

import visitAstFixup from './visitors/fixAst'
import visitPlaceholders from './visitors/placeholders'
import visitOptionalChains from './visitors/optionalChains'
import visitMain from './visitors/main'
import firstPass from './visitors/firstPass'
import secondPass from './visitors/secondPass'
import thirdPass from './visitors/thirdPass'
import mainPass from './visitors/main'

export default LightScript(babel) ->
plugin = {
Expand Down Expand Up @@ -49,14 +49,13 @@ export default LightScript(babel) ->

////////// AST visitation and transformation
// First pass: Perform basic ast fixups (block bodies, etc)
compiler~visitAstFixup(path)
// Second pass: transform placeholders
if compiler.opts.placeholderArgs:
compiler~visitPlaceholders(path)
compiler~firstPass(path)
// Second pass: placeholders, comprehensions
compiler~secondPass(path)
// Third pass: transform optional chains
compiler~visitOptionalChains(path)
compiler~thirdPass(path)
// Main ast visitor
compiler~visitMain(path)
compiler~mainPass(path)

////////// Post-processing
// Fix up loose ends like adding `import` statements
Expand Down
55 changes: 3 additions & 52 deletions src/lscNodeTypes.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -49,67 +49,18 @@ export registerLightscriptNodeTypes(t): void ->
},
});

if not t.hasType("ArrayComprehension"):
definePluginType("ArrayComprehension", {
visitor: ["loop", "elements"],
aliases: ["ArrayExpression", "Expression"],
fields: {
loop: { // compatibility with vanilla lsc comprehensions
validate: assertNodeType("ForStatement")
optional: true
}
elements: {
validate: chain(
assertValueType("array")
assertEach(assertNodeType("Expression", "SpreadElement", "Comprehension"))
)
optional: true
}
},
});

if not t.hasType("ObjectComprehension"):
definePluginType("ObjectComprehension", {
visitor: ["loop", "properties"],
aliases: ["ObjectExpression", "Expression"],
fields: {
loop: { // compatibility with vanilla lsc comprehensions
validate: assertNodeType("ForStatement")
optional: true
}
properties: {
validate: chain(
assertValueType("array")
assertEach(assertNodeType("ObjectProperty", "SpreadProperty", "Comprehension"))
)
optional: true
}
},
});

if not t.hasType("LoopComprehension"):
definePluginType("LoopComprehension", {
if not t.hasType("SpreadLoop"):
definePluginType("SpreadLoop", {
builder: ["loop"]
visitor: ["loop"]
aliases: ["Comprehension"]
aliases: ["Expression"]
fields: {
loop: {
validate: assertNodeType("ForStatement")
}
}
})

if not t.hasType("CaseComprehension"):
definePluginType("CaseComprehension", {
visitor: ["conditional"]
aliases: ["Comprehension"]
fields: {
conditional: {
validate: assertNodeType("IfStatement")
}
}
})

if not t.hasType("NamedArrowDeclaration"):
definePluginType("NamedArrowDeclaration", {
builder: ["id", "params", "body", "skinny", "async", "generator"],
Expand Down
7 changes: 6 additions & 1 deletion src/transforms/classes.lsc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import t, { is } from '../types'

// prevent generated spreadexpr from being further transformed
safe(node) ->
node._safe = true
node

// Check if the given path or any of its descendants contains a `super()`
// call expression.
export containsSuperCall(path) ->
Expand Down Expand Up @@ -61,7 +66,7 @@ export ensureConstructor(classPath, constructorBodyPath, withSuper = true) ->
constructorBodyPath.parentPath.node.params = [t.restElement(argsUid)];
t.expressionStatement(
t.callExpression(t.super(), [
t.spreadElement(argsUid)
t.spreadElement(argsUid)~safe!
])
)

Expand Down
Loading

0 comments on commit ee270bf

Please sign in to comment.