krl-compiler
Advanced tools
Comparing version 0.9.0 to 0.10.0
{ | ||
"name": "krl-compiler", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "KRL compiler", | ||
@@ -47,4 +47,5 @@ "main": "src/index.js", | ||
"lodash": "^4.13.1", | ||
"minimist": "^1.2.0", | ||
"to-js-identifier": "^1.0.0" | ||
} | ||
} |
var _ = require('lodash'); | ||
var wrapKRLType = require('../utils/wrapKRLType'); | ||
@@ -11,3 +10,3 @@ module.exports = function(ast, comp, e){ | ||
fn_body.push(e('var', 'matches', | ||
e('call', e('id', 'ctx.event.attrs.getMatches'), [ | ||
e('call', e('id', 'ctx.event.getAttrMatches'), [ | ||
e('array', _.map(ast.attributes, function(a){ | ||
@@ -31,5 +30,3 @@ return e('array', [ | ||
e('str', s.value, s.loc), | ||
wrapKRLType(e, 'String', [ | ||
e('get', e('id', 'matches', s.loc), e('num', 0, s.loc), s.loc) | ||
]) | ||
e('get', e('id', 'matches', s.loc), e('num', 0, s.loc), s.loc) | ||
], s.loc), s.loc)); | ||
@@ -36,0 +33,0 @@ }); |
var _ = require('lodash'); | ||
//TODO remove from package.json var toId = require('to-js-identifier'); | ||
var mkTree = require('estree-builder'); | ||
var wrapKRLType = require('./utils/wrapKRLType'); | ||
var callStdLibFn = require('./utils/callStdLibFn'); | ||
@@ -13,6 +12,6 @@ | ||
'String': function(ast, comp, e){ | ||
return wrapKRLType(e, 'String', [e('string', ast.value)]); | ||
return e('string', ast.value); | ||
}, | ||
'Number': function(ast, comp, e){ | ||
return wrapKRLType(e, 'Number', [e('number', ast.value)]); | ||
return e('number', ast.value); | ||
}, | ||
@@ -24,3 +23,3 @@ 'Identifier': function(ast, comp, e){ | ||
if(ast.value.length < 1){ | ||
return wrapKRLType(e, 'String', []); | ||
return e('string', ''); | ||
} | ||
@@ -39,6 +38,6 @@ var compElm = function(elm){ | ||
} | ||
return wrapKRLType(e, 'String', [curr]); | ||
return curr; | ||
}, | ||
'Boolean': function(ast, comp, e){ | ||
return wrapKRLType(e, 'Boolean', [e(ast.value ? 'true' : 'false')]); | ||
return e(ast.value ? 'true' : 'false'); | ||
}, | ||
@@ -53,3 +52,3 @@ 'RegExp': function(ast, comp, e){ | ||
} | ||
return wrapKRLType(e, 'RegExp', [ | ||
return e('new', e('id', 'RegExp'), [ | ||
e('str', ast.value.source), | ||
@@ -89,2 +88,15 @@ e('str', flags) | ||
'Application': function(ast, comp, e){ | ||
if(ast.callee.type === 'MemberExpression' | ||
&& ast.callee.method === 'dot' | ||
&& ast.callee.property.type === 'Identifier' | ||
){ | ||
//operator syntax is just sugar | ||
var operator = ast.callee.property; | ||
var callee = e('get', | ||
e('id', 'ctx.krl.stdlib', operator.loc), | ||
e('string', operator.value, operator.loc), | ||
operator.loc | ||
); | ||
return e('call', callee, [comp(ast.callee.object)].concat(comp(ast.args))); | ||
} | ||
return e('call', comp(ast.callee), [ | ||
@@ -91,0 +103,0 @@ e('id', 'ctx'), |
Sorry, the diff of this file is not supported yet
17927
498
8
10
+ Addedminimist@^1.2.0
+ Addedminimist@1.2.8(transitive)