Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yurine

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yurine - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

test/test.js

394

index.js

@@ -1,1 +0,393 @@

module.exports = require('./build/yurine')['default'];
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('homunculus')) :
typeof define === 'function' && define.amd ? define(['homunculus'], factory) :
(global = global || self, global.yurine = factory(global.homunculus));
}(this, function (homunculus) { 'use strict';
homunculus = homunculus && homunculus.hasOwnProperty('default') ? homunculus['default'] : homunculus;
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var ES6Token = homunculus.getClass('token', 'js');
var Token = homunculus.getClass('token', 'csx');
var Node = homunculus.getClass('node', 'csx');
var S = {};
S[Token.LINE] = S[Token.COMMENT] = S[Token.BLANK] = true;
var res;
var append;
function ignore(node, includeLine) {
if (node instanceof Token || node instanceof ES6Token) {
if (node.isVirtual()) {
return;
}
node.ignore = true;
append = '';
while (node = node.next()) {
if (node.isVirtual() || !S.hasOwnProperty(node.type())) {
break;
}
var s = node.content();
res += s;
append += s;
if (includeLine || s != '\n') {
node.ignore = true;
}
}
} else if (node.isToken()) {
ignore(node.token(), includeLine);
} else {
node.leaves().forEach(function (leaf) {
ignore(leaf, includeLine);
});
}
}
function parse(node, includeLine) {
res = '';
append = '';
ignore(node, includeLine);
return {
res: res,
append: append
};
}
parse.S = S;
var JsNode = homunculus.getClass('Node', 'es6');
var Token$1 = homunculus.getClass('Token');
function join (node, word) {
var res = recursion(node, {
's': '',
'word': word
});
return res.s;
}
function recursion(node, res) {
var isToken = node.name() === JsNode.TOKEN;
var isVirtual = isToken && node.token().type() === Token$1.VIRTUAL;
if (isToken) {
var token = node.token();
if (!isVirtual) {
if (res.word && [Token$1.ID, Token$1.NUMBER, Token$1.KEYWORD].indexOf(token.type()) > -1) {
res.s += ' ';
}
if (token.content() === '}' && res.s.charAt(res.s.length - 1) === ';') {
res.s = res.s.replace(/;$/, '');
}
res.s += token.content();
res.word = [Token$1.ID, Token$1.NUMBER, Token$1.KEYWORD].indexOf(token.type()) > -1;
} else if (token.content() === ';') {
res.s += ';';
res.word = false;
}
} else {
node.leaves().forEach(function (leaf) {
recursion(leaf, res);
});
}
return res;
}
var Token$2 = homunculus.getClass('token', 'csx');
var Node$1 = homunculus.getClass('node', 'csx');
function elem(node) {
var res = ''; //open和selfClose逻辑复用
res += selfClose(node.first());
res += ',[';
var comma = false;
for (var i = 1, len = node.size(); i < len - 1; i++) {
var leaf = node.leaf(i);
switch (leaf.name()) {
case Node$1.CSXChild:
if (comma) {
res += ',';
comma = false;
}
res += child(leaf);
comma = true;
break;
case Node$1.TOKEN:
var s = leaf.token().content(); //open和close之间的空白不能忽略
if (/^\s+$/.test(s)) {
if (leaf.prev().name() === Node$1.CSXOpeningElement && leaf.next().name() === Node$1.CSXClosingElement) {
res += '"' + s.replace(/"/g, '\\"').replace(/\n/g, '\\n\\\n') + '"';
} else {
res += s;
}
} else {
if (comma) {
res += ',';
comma = false;
}
res += '"' + s.replace(/"/g, '\\"').replace(/\n/g, '\\n\\\n') + '"';
comma = true;
}
break;
default:
if (comma) {
res += ',';
comma = false;
}
res += parse$1(leaf);
comma = true;
}
}
res += '])';
if (node.last().name() === Node$1.CSXClosingElement) {
res += parse(node.last(), true).res;
}
return res;
}
function selfClose(node) {
var res = '';
var name;
var first = node.leaf(1);
if (first.isToken()) {
name = first.token().content();
} else if (first.name() === Node$1.CSXMemberExpression) {
name = first.first().token().content();
for (var i = 1, len = first.size(); i < len; i++) {
name += first.leaf(i).token().content();
}
}
if (/^[A-Z]/.test(name)) {
res += 'karas.createCp(';
res += name;
} else if (/^\$/.test(name)) {
res += 'karas.createGm(';
res += '"' + name + '"';
} else {
res += 'karas.createVd(';
res += '"' + name + '"';
}
res += ',[';
for (var _i = 2, _len = node.size(); _i < _len - 1; _i++) {
var leaf = node.leaf(_i);
if (_i !== 2) {
res += ',';
}
switch (leaf.name()) {
case Node$1.CSXBindAttribute:
res += attr(leaf);
break;
case Node$1.CSXAttribute:
res += attr(leaf);
break;
case Node$1.CSXSpreadAttribute:
res += spread(leaf);
break;
}
}
res += ']';
return res;
}
function attr(node) {
var res = '';
var key = node.first().token().content();
var name = node.parent().leaf(1).token().content();
var isCp = /^[A-Z]/.test(name);
var k = '["' + key + '"';
res += k + ',';
var v = node.last();
if (v.isToken()) {
v = v.token().content();
res += v;
} else {
res += child(v);
}
res += ']';
return res;
}
function spread(node) {
return join(node.leaf(2));
}
function child(node) {
return new Tree().parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1');
}
function parse$1(node) {
var res = '';
switch (node.name()) {
case Node$1.CSXElement:
res += elem(node);
break;
case Node$1.CSXSelfClosingElement:
res += selfClose(node);
res += ')';
break;
}
return res;
}
var Node$2 = homunculus.getClass('node', 'csx');
var Tree =
/*#__PURE__*/
function () {
function Tree() {
_classCallCheck(this, Tree);
this.res = '';
}
_createClass(Tree, [{
key: "parse",
value: function parse(node) {
this.recursion(node, false);
return this.res;
}
}, {
key: "recursion",
value: function recursion(node) {
var self = this;
var isToken = node.isToken();
if (isToken) {
var token = node.token();
if (token.isVirtual()) {
return;
}
if (!token.ignore) {
this.res += token.content();
}
while (token.next()) {
token = token.next();
if (token.isVirtual() || !parse.S.hasOwnProperty(token.type())) {
break;
}
if (!token.ignore) {
this.res += token.content();
}
}
} else {
switch (node.name()) {
case Node$2.CSXElement:
case Node$2.CSXSelfClosingElement:
this.res += parse$1(node);
return;
}
node.leaves().forEach(function (leaf) {
self.recursion(leaf);
});
}
}
}]);
return Tree;
}();
var Yurine =
/*#__PURE__*/
function () {
function Yurine() {
_classCallCheck(this, Yurine);
this.parser = null;
this.node = null;
}
_createClass(Yurine, [{
key: "parse",
value: function parse(code) {
this.parser = homunculus.getParser('csx');
this.node = this.parser.parse(code);
var tree = new Tree();
return tree.parse(this.node);
}
}, {
key: "tokens",
value: function tokens() {
return this.ast ? this.parser.lexer.tokens() : null;
}
}, {
key: "ast",
value: function ast() {
return this.node;
}
}], [{
key: "parse",
value: function parse(code) {
return new Yurine().parse(code);
}
}]);
return Yurine;
}();
var index = new Yurine();
return index;
}));
//# sourceMappingURL=index.js.map

23

package.json
{
"name": "yurine",
"version": "0.2.0",
"description": "A CSX transformer for karas",
"version": "0.3.0",
"description": "A csx transformer for karas",
"author": "army8735 <army8735@qq.com>",

@@ -19,6 +19,5 @@ "maintainers": [

"scripts": {
"build": "gulp",
"dev": "gulp watch",
"pack": "rollup -c rollup.config.js",
"test": "make test"
"build": "rollup -c rollup.config.js",
"dev": "rollup -c rollup.config.js --watch",
"test": "mocha test/test.js -R spec"
},

@@ -35,15 +34,7 @@ "repository": {

"@babel/preset-env": "^7.4.3",
"babel-loader": "^8.0.4",
"blanket": "^1.1.6",
"coveralls": "^2.11.2",
"expect.js": "^0.3.1",
"gulp": "^3.9.0",
"gulp-rimraf": "^0.2.2",
"gulp-util": "^3.0.1",
"mocha": "^2.2.4",
"mocha-lcov-reporter": "^0.0.2",
"mocha": "^6.2.1",
"rollup": "^1.21.2",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-sourcemaps": "^0.4.2",
"through2": "^3.0.0"
"rollup-plugin-sourcemaps": "^0.4.2"
},

@@ -50,0 +41,0 @@ "main": "./index",

# yurine(百合音)
[![NPM version](https://badge.fury.io/js/yurine.png)](https://npmjs.org/package/yurine)
[![Build Status](https://travis-ci.org/karasjs/yurine.svg?branch=master)](https://travis-ci.org/karasjs/yurine)
[![Dependency Status](https://david-dm.org/karasjs/yurine.png)](https://david-dm.org/karasjs/yurine)

@@ -7,3 +7,3 @@ import babel from 'rollup-plugin-babel';

name: 'yurine',
file: 'yurine.js',
file: 'index.js',
format: 'umd',

@@ -10,0 +10,0 @@ sourcemap: true,

import homunculus from 'homunculus';
import InnerTree from './InnerTree';
import linkage from './linkage';
import Tree from './Tree';
import ignore from './ignore';
import join from './join';
import join2 from './join2';
import delegate from './delegate';

@@ -12,6 +9,6 @@ let Token = homunculus.getClass('token', 'csx');

function elem(node, opt, param) {
function elem(node) {
let res = '';
//open和selfClose逻辑复用
res += selfClose(node.first(), opt, param);
res += selfClose(node.first());
res += ',[';

@@ -27,3 +24,3 @@ let comma = false;

}
res += child(leaf, opt, param);
res += child(leaf);
comma = true;

@@ -56,3 +53,3 @@ break;

}
res += parse(leaf, opt, param);
res += parse(leaf);
comma = true;

@@ -67,3 +64,3 @@ }

}
function selfClose(node, opt, param) {
function selfClose(node) {
let res = '';

@@ -101,6 +98,6 @@ let name;

case Node.CSXBindAttribute:
res += attr(leaf, opt, param);
res += attr(leaf);
break;
case Node.CSXAttribute:
res += attr(leaf, opt, param);
res += attr(leaf);
break;

@@ -115,3 +112,3 @@ case Node.CSXSpreadAttribute:

}
function attr(node, opt, param) {
function attr(node) {
let res = '';

@@ -121,9 +118,2 @@ let key = node.first().token().content();

let isCp = /^[A-Z]/.test(name);
if(key.charAt(0) === '@') {
key = key.slice(1);
}
// 组件属性非@申明均不bind
else if(isCp && opt.isBind) {
opt.isBind = false;
}
let k = '["' + key + '"';

@@ -136,7 +126,4 @@ res += k + ',';

}
else if(/^on-?[a-zA-Z]/.test(key)) {
res += onEvent(v, opt, param);
}
else {
res += child(v, opt, param, true);
res += child(v);
}

@@ -146,177 +133,17 @@ res += ']';

}
function onEvent(node, opt, param) {
return delegate(node, param);
}
function spread(node) {
return join(node.leaf(2));
}
function child(node, opt, param, isAttr) {
let callexpr = node.leaf(1);
if(opt.isBind) {
let temp = linkage(callexpr, param, {
arrowFn: opt.arrowFn,
});
let list = temp.arr;
let single = temp.single;
let bind = temp.bind;
if(list.length) {
let listener = list.length === 1
? ('"' + list[0] + '"')
: JSON.stringify(list);
if(isAttr) {
let key = node.prev().prev().token().content();
if(key === 'value' || key === 'checked' || key === 'selected') {
let tag = node.parent().parent().leaf(1).token().content();
if(tag === 'input' || tag === 'select' || tag === 'option') {
let value = node.leaf(1);
// 单独值mmbexpr非运算符双向绑定,其余单向
if(value.name() === Node.MMBEXPR) {
let v = join2(value);
return 'new yurine.Obj('
+ listener
+ ',()=>{return('
+ new InnerTree(opt, param).parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1')
+ ')}'
+ (single ? ',true' : ',false')
+ (bind ?
(',(v)=>{v!=='
+ v
+ '&&('
+ v
+ '=v)})')
: ')');
}
return 'new yurine.Obj('
+ listener
+ ',()=>{return('
+ new InnerTree(opt, param).parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1')
+ ')}'
+ (single ? ',true' : '')
+ ')';
}
}
}
else if(node.prev() && node.prev().name() === Node.CSXOpeningElement) {
let key = node.prev().leaf(1).token().content();
if(key === 'textarea') {
let value = node.leaf(1);
if(value.name() === Node.MMBEXPR) {
let v = join2(value);
return 'new yurine.Obj('
+ listener
+ ',()=>{return('
+ new InnerTree(opt, param).parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1')
+ ')}'
+ (single ? ',true' : ',false')
+ (bind ?
(',(v)=>{v!=='
+ v
+ '&&('
+ v
+ '=v)})')
: ')');
}
}
}
return 'new yurine.Obj('
+ listener
+ ',()=>{return('
+ new InnerTree(opt, param).parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1')
+ ')}'
+ (single ? ',true' : '')
+ ')';
}
}
// Obj中再次出现的:input的value还需要添加Obj
else if(opt.isInBind) {
if(isAttr) {
let key = node.prev().prev().token().content();
if(key === 'value') {
let tag = node.parent().parent().leaf(1).token().content();
if(tag === 'input' || tag === 'select') {
let temp = linkage(callexpr, param, {
arrowFn: opt.arrowFn,
});
let list = temp.arr;
let bind = temp.bind;
if(list.length) {
let value = node.leaf(1);
let listener = list.length === 1
? ('"' + list[0] + '"')
: JSON.stringify(list);
if(value.name() === Node.MMBEXPR) {
let v = join2(value);
return 'new yurine.Obj('
+ listener
+ ',()=>{return('
+ new InnerTree(opt, param).parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1')
+ ')}'
+ ',false'
+ (bind ?
(',(v)=>{v!=='
+ v
+ '&&('
+ v
+ '=v)})')
: ')');
}
return 'new yurine.Obj('
+ listener
+ ',()=>{return('
+ new InnerTree(opt, param).parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1')
+ ')})';
}
}
}
}
else if(node.prev() && node.prev().name() === Node.CSXOpeningElement) {
let key = node.prev().leaf(1).token().content();
if(key === 'textarea') {
let temp = linkage(callexpr, param, {
arrowFn: opt.arrowFn,
});
let list = temp.arr;
let bind = temp.bind;
if(list.length) {
let value = node.leaf(1);
let listener = list.length === 1
? ('"' + list[0] + '"')
: JSON.stringify(list);
if(value.name() === Node.MMBEXPR) {
let v = join2(value);
return 'new yurine.Obj('
+ listener
+ ',()=>{return('
+ new InnerTree(opt, param).parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1')
+ ')}'
+ ',false'
+ (bind ?
(',(v)=>{v!=='
+ v
+ '&&('
+ v
+ '=v)})')
: ')');
}
return 'new yurine.Obj('
+ listener
+ ',()=>{return('
+ new InnerTree(opt, param).parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1')
+ ')})';
}
}
}
}
return new InnerTree(opt, param).parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1');
function child(node) {
return new Tree().parse(node).replace(/^(\s*){/, '$1').replace(/}(\s*)$/, '$1');
}
function parse(node, opt, param) {
function parse(node) {
let res = '';
switch(node.name()) {
case Node.CSXElement:
res += elem(node, opt, param);
res += elem(node);
break;
case Node.CSXSelfClosingElement:
res += selfClose(node, opt, param);
res += selfClose(node);
res += ')';

@@ -323,0 +150,0 @@ break;

@@ -1,5 +0,27 @@

'use strict';
import homunculus from 'homunculus';
import Tree from './Tree';
import Yurine from './yurine';
class Yurine {
constructor() {
this.parser = null;
this.node = null;
}
parse(code) {
this.parser = homunculus.getParser('csx');
this.node = this.parser.parse(code);
let tree = new Tree();
return tree.parse(this.node);
}
tokens() {
return this.ast ? this.parser.lexer.tokens() : null;
}
ast() {
return this.node;
}
export default Yurine;
static parse(code) {
return new Yurine().parse(code);
}
}
export default new Yurine();
import homunculus from 'homunculus';
import csx from './csx';
import ignore from './ignore';
import render from './render';
import join2 from './join2';

@@ -17,3 +15,3 @@ let Node = homunculus.getClass('node', 'csx');

}
recursion(node, inClass) {
recursion(node) {
let self = this;

@@ -43,323 +41,12 @@ let isToken = node.isToken();

case Node.CSXSelfClosingElement:
this.res += csx(node, {}, this.param);
this.res += csx(node, {});
return;
case Node.CLASSDECL:
inClass = this.klass(node);
break;
case Node.CLASSEXPR:
inClass = this.klass(node);
break;
case Node.CLASSBODY:
if(inClass) {
this.param = {
getHash: {},
setHash: {},
evalHash: {},
bindHash: {},
linkHash: {},
linkedHash: {},
};
this.list(node);
}
break;
case Node.METHOD:
let isRender = this.method(node);
if(isRender) {
this.res += render(node, this.param || {});
return;
}
break;
case Node.ANNOT:
if(['@bind', '@eval', '@link'].indexOf(node.first().token().content()) > -1) {
this.res += ignore(node, true).res;
}
else {
this.res += join2(node);
}
return;
case Node.LEXBIND:
if(inClass && node.parent().name() === Node.CLASSELEM) {
this.res += this.bindLex(node);
return;
}
break;
}
node.leaves().forEach(function(leaf) {
self.recursion(leaf, inClass);
self.recursion(leaf);
});
switch(node.name()) {
case Node.FNBODY:
this.fnbody(node, inClass);
break;
case Node.CLASSDECL:
inClass = false;
break;
case Node.CLASSEXPR:
inClass = false;
break;
}
}
}
klass(node) {
let heritage = node.leaf(2);
if(heritage && heritage.name() === Node.HERITAGE) {
let body = node.last().prev();
let leaves = body.leaves();
for(let i = 0, len = leaves.length; i < len; i++) {
let leaf = leaves[i];
let method = leaf.first();
if(method.name() === Node.METHOD) {
let first = method.first();
if(first.name() === Node.PROPTNAME) {
let id = first.first();
if(id.name() === Node.LTRPROPT) {
id = id.first();
if(id.isToken()) {
id = id.token().content();
if(id === 'constructor') {
return true;
}
}
}
}
}
}
}
return false;
}
method(node) {
let first = node.first();
if(first.name() === Node.PROPTNAME) {
first = first.first();
if(first.name() === Node.LTRPROPT) {
first = first.first();
if(first.isToken() && first.token().content() === 'render') {
return true;
}
}
}
}
fnbody(node, inClass) {
if(!inClass) {
return;
}
let parent = node.parent();
if(parent.name() === Node.METHOD) {
let setV;
let first = parent.first();
if(first.isToken() && first.token().content() === 'set') {
let fmparams = parent.leaf(3);
if(fmparams && fmparams.name() === Node.FMPARAMS) {
let single = fmparams.first();
if(single && single.name() === Node.SINGLENAME) {
let bindid = single.first();
if(bindid && bindid.name() === Node.BINDID) {
setV = bindid.first().token().content();
}
}
}
let name = parent.leaf(1).first().first().token().content();
let prev = parent.parent().prev();
let ids = [];
if(prev) {
prev = prev.first();
if (prev.name() === Node.ANNOT && ['@bind', '@eval'].indexOf(prev.first().token().content()) > -1) {
ids.push(name);
}
}
ids = ids.concat(this.param.linkedHash[name] || []);
if(ids.length) {
if(setV) {
if(ids.length === 1) {
this.res += ';this.__array("';
this.res += ids[0] + '",';
this.res += setV;
this.res += ')';
}
else {
this.res += ';this.__array(["';
this.res += ids.join('","') + '"],';
this.res += setV;
this.res += ')';
}
}
if(ids.length === 1) {
this.res += ';this.__data("';
this.res += ids[0];
this.res += '")';
}
else {
this.res += ';this.__data(["';
this.res += ids.join('","');
this.res += '"])';
}
}
}
}
}
list(node) {
let leaves = node.leaves();
let length = leaves.length;
for(let i = 0; i < length; i++) {
let item = leaves[i].first();
if(item.name() === Node.ANNOT) {
let annot = item.first().token().content();
let method = leaves[i+1] ? leaves[i+1].first() : null;
if(method && method.name() === Node.METHOD) {
let first = method.first();
if(first.isToken()) {
let token = first.token().content();
if(token === 'set' && annot === '@bind') {
let name = first.next().first().first().token().content();
this.param.bindHash[name] = true;
}
else if(token === 'set' && annot === '@eval') {
let name = first.next().first().first().token().content();
this.param.evalHash[name] = true;
}
else if(token === 'get' && annot === '@link') {
let name = first.next().first().first().token().content();
this.param.linkHash[name] = this.param.linkHash[name] || [];
let params = item.leaf(2);
if(params && params.name() === Node.FMPARAMS) {
params.leaves().forEach(function(param) {
if(param.name() === Node.SINGLENAME) {
param = param.first();
if(param.name() === Node.BINDID) {
param = param.first();
if(param.isToken()) {
param = param.token().content();
this.param.linkHash[name].push(param);
this.param.linkedHash[param] = this.param.linkedHash[param] || [];
this.param.linkedHash[param].push(name);
}
}
}
}.bind(this));
}
}
}
}
else if(method && method.name() === Node.LEXBIND) {
let first = method.first();
if(first.name() === Node.BINDID) {
let name = first.first().token().content();
parseLex(this.param, name, item, annot);
}
}
//连续2个
else if(method && method.name() === Node.ANNOT) {
let item2 = method;
let annot2 = method.first().token().content();
method = leaves[i+2] ? leaves[i+2].first() : null;
if(method && method.name() === Node.LEXBIND) {
let first = method.first();
if(first.name() === Node.BINDID) {
let name = first.first().token().content();
parseLex(this.param, name, item, annot);
parseLex(this.param, name, item2, annot2);
}
}
}
}
else if(item.name() === Node.METHOD) {
let first = item.first();
if(first.isToken()) {
let token = first.token().content();
let name = first.next().first().first().token().content();
if(token === 'get') {
this.param.getHash[name] = true;
}
else if(token === 'set') {
this.param.setHash[name] = true;
}
}
}
else if(item.name() === Node.LEXBIND) {
let first = item.first();
if(first.name() === Node.BINDID) {
let name = first.first().token().content();
this.param.getHash[name] = true;
this.param.setHash[name] = true;
}
}
}
}
bindLex(node) {
let parent = node.parent();
let bindid = node.first();
if(bindid.name() === Node.BINDID) {
let token = bindid.first();
let name = token.token().content();
let init = node.leaf(1);
let ids = [];
let prev = parent.prev();
if(prev) {
prev = prev.first();
if(prev.name() === Node.ANNOT && ['@bind', '@eval'].indexOf(prev.first().token().content()) > -1) {
ids.push(name);
}
}
ids = ids.concat(this.param.linkedHash[name] || []);
let s = '';
s += 'set ' + name + '(v){';
s += 'this.__setBind("' + name + '",v)';
if(ids.length) {
if(ids.length === 1) {
s += ';this.__data("';
s += ids[0];
s += '")';
}
else {
s += ';this.__data(["';
s += ids.join('","');
s += '"])';
}
}
s += '}get ' + name + '(){';
s += ignore(token).res;
if(init) {
s += 'if(this.__initBind("' + name + '"))';
s += 'this.__setBind("' + name + '",';
s += ignore(init.first()).res;
s += join2(init.last());
s += ');';
}
s += 'return this.__getBind("' + name + '")}';
return s;
}
}
}
function parseLex(param, name, item, annot) {
if(annot === '@bind') {
param.bindHash[name] = true;
}
else if(annot === '@eval') {
param.evalHash[name] = true;
}
else if(annot === '@link') {
param.linkHash[name] = param.linkHash[name] || [];
let params = item.leaf(2);
if(params && params.name() === Node.FMPARAMS) {
params.leaves().forEach(function(item) {
if(item.name() === Node.SINGLENAME) {
item = item.first();
if(item.name() === Node.BINDID) {
item = item.first();
if(item.isToken()) {
item = item.token().content();
param.linkHash[name].push(item);
param.linkedHash[item] = param.linkedHash[item] || [];
param.linkedHash[item].push(name);
}
}
}
});
}
}
}
export default Tree;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc