From 58c571b28445d75d7e67c6a34ec4421b9a95f97b Mon Sep 17 00:00:00 2001 From: mohayonao Date: Mon, 16 Jun 2014 21:22:16 +0900 Subject: [PATCH] :bug: fix #77 compile error - add test - fix bug - build v0.0.56 --- package.json | 2 +- src/sc/lang/compiler/pre-compiler.js | 6 +- src/sc/lang/compiler/test-cases.js | 166 +++++++++++++++++++++++++++ 3 files changed, 170 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 2222c13..0b7f8dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scscript", - "version": "0.0.55", + "version": "0.0.56", "author": "Nao Yonamine ", "homepage": "http://mohayonao.github.io/SCScript/", "bugs": "https://github.com/mohayonao/SCScript/issues", diff --git a/src/sc/lang/compiler/pre-compiler.js b/src/sc/lang/compiler/pre-compiler.js index 994b4a0..0b6fb91 100644 --- a/src/sc/lang/compiler/pre-compiler.js +++ b/src/sc/lang/compiler/pre-compiler.js @@ -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"; } diff --git a/src/sc/lang/compiler/test-cases.js b/src/sc/lang/compiler/test-cases.js index 7d9e539..6d00318 100644 --- a/src/sc/lang/compiler/test-cases.js +++ b/src/sc/lang/compiler/test-cases.js @@ -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 } + } + } } };