Skip to content

Commit

Permalink
🐛 fix #77 compile error
Browse files Browse the repository at this point in the history
- add test
- fix bug
- build v0.0.56
  • Loading branch information
mohayonao committed Jun 16, 2014
1 parent 35fdf9b commit 58c571b
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scscript",
"version": "0.0.55",
"version": "0.0.56",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
6 changes: 3 additions & 3 deletions src/sc/lang/compiler/pre-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@
};

function isFunctionExpression(node) {
return node.type === Syntax.FunctionExpression;
return node && node.type === Syntax.FunctionExpression;
}

function isSegmentedMethod(node) {
return node.type === Syntax.CallExpression &&
return node && node.type === Syntax.CallExpression &&
(SegmentedMethod.hasOwnProperty(node.method.name) || isValueMethod(node));
}

function isValueMethod(node) {
return node.type === Syntax.CallExpression &&
return node && node.type === Syntax.CallExpression &&
node.method.name.substr(0, 5) === "value";
}

Expand Down
166 changes: 166 additions & 0 deletions src/sc/lang/compiler/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -8515,6 +8515,172 @@
end : { line: 1, column: 16 }
}
}
},
"{ (..10).do(_.yield) }": {
compiled: [
"SCScript(function($) {",
" return $.Function(function() {",
" return [",
" function() {",
" return $.Integer(0).$('series', [ " +
"null, $.Integer(10) ]).$('do', [ $.Function(function() {",
" var $_0;",
" return [",
" function(_arg0) {",
" $_0 = _arg0;",
" return $_0.$('yield');",
" }",
" ];",
" }) ]);",
" }",
" ];",
" });",
"});"
],
ast: {
type: Syntax.Program,
body: [
{
type: Syntax.FunctionExpression,
body: [
{
type: Syntax.CallExpression,
callee: {
type: Syntax.CallExpression,
callee: {
type: Syntax.Literal,
value: "0",
valueType: Token.IntegerLiteral,
range: [ 3, 3 ],
loc: {
start: { line: 1, column: 3 },
end : { line: 1, column: 3 }
}
},
method: {
type: Syntax.Identifier,
name: "series",
range: [ 3, 3 ],
loc: {
start: { line: 1, column: 3 },
end : { line: 1, column: 3 }
}
},
args: {
list: [
null,
{
type: Syntax.Literal,
value: "10",
valueType: Token.IntegerLiteral,
range: [ 5, 7 ],
loc: {
start: { line: 1, column: 5 },
end : { line: 1, column: 7 }
}
}
]
},
range: [ 2, 8 ],
loc: {
start: { line: 1, column: 2 },
end : { line: 1, column: 8 }
}
},
method: {
type: Syntax.Identifier,
name: "do",
range: [ 9, 11 ],
loc: {
start: { line: 1, column: 9 },
end : { line: 1, column: 11 }
}
},
args: {
list: [
{
type: Syntax.FunctionExpression,
args: {
list: [
{
type: Syntax.VariableDeclarator,
id: {
type: Syntax.Identifier,
name: "$_0",
range: [ 12, 13 ],
loc: {
start: { line: 1, column: 12 },
end : { line: 1, column: 13 }
}
},
range: [ 12, 13 ],
loc: {
start: { line: 1, column: 12 },
end : { line: 1, column: 13 }
}
}
]
},
body: [
{
type: Syntax.CallExpression,
callee: {
type: Syntax.Identifier,
name: "$_0",
range: [ 12, 13 ],
loc: {
start: { line: 1, column: 12 },
end : { line: 1, column: 13 }
}
},
method: {
type: Syntax.Identifier,
name: "yield",
range: [ 14, 19 ],
loc: {
start: { line: 1, column: 14 },
end : { line: 1, column: 19 }
},
},
args: {
list: []
},
range: [ 12, 19 ],
loc: {
start: { line: 1, column: 12 },
end : { line: 1, column: 19 }
}
}
],
partial: true,
range: [ 12, 19 ],
loc: {
start: { line: 1, column: 12 },
end : { line: 1, column: 19 }
}
}
]
},
range: [ 2, 20 ],
loc: {
start: { line: 1, column: 2 },
end : { line: 1, column: 20 }
},
}
],
range: [ 0, 22 ],
loc: {
start: { line: 1, column: 0 },
end : { line: 1, column: 22 }
},
}
],
range: [ 0, 22 ],
loc: {
start: { line: 1, column: 0 },
end : { line: 1, column: 22 }
}
}
}
};

Expand Down

0 comments on commit 58c571b

Please sign in to comment.