Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决出现0==i或者0===i的类似判定时候,提取变量bug #22

Closed
wants to merge 1 commit into from

Conversation

uc2dabing
Copy link

如果模板出现类似if(0==i)或者if(0===i)的时候,提取变量bug,会把0也作为变量提取出来。
debug代码如下:
var $helpers=this,0=$data.0,i=$data.i,

如果模板出现类似if(0==i)或者if(0===i)的时候,提取变量bug,会把0也作为变量提取出来。
aui pushed a commit that referenced this pull request May 17, 2013
aui pushed a commit that referenced this pull request May 17, 2013
@aui
Copy link
Owner

aui commented May 17, 2013

变量静态分析的算法已经更新

// 静态分析模板变量
var KEYWORDS =
    // 关键字
    'break,case,catch,continue,debugger,default,delete,do,else,false'
    + ',finally,for,function,if,in,instanceof,new,null,return,switch,this'
    + ',throw,true,try,typeof,var,void,while,with'

    // 保留字
    + ',abstract,boolean,byte,char,class,const,double,enum,export,extends'
    + ',final,float,goto,implements,import,int,interface,long,native'
    + ',package,private,protected,public,short,static,super,synchronized'
    + ',throws,transient,volatile'

    // ECMA 5 - use strict
    + ',arguments,let,yield'

    + ',undefined';
var REMOVE_RE = /\/\*(?:.|\n)*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|'[^']*'|"[^"]*"|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g;
var SPLIT_RE = /[^\w$]+/g;
var KEYWORDS_RE = new RegExp(["\\b" + KEYWORDS.replace(/,/g, '\\b|\\b') + "\\b"].join('|'), 'g');
var NUMBER_RE = /\b\d[^,]*/g;
var BOUNDARY_RE = /^,+|,+$/g;
var getVariable = function (code) {

    code = code
    .replace(REMOVE_RE, '')
    .replace(SPLIT_RE, ',')
    .replace(KEYWORDS_RE, '')
    .replace(NUMBER_RE, '')
    .replace(BOUNDARY_RE, '');

    code = code ? code.split(/,+/) : [];

    return code;
};

@aui aui closed this May 17, 2013
@aui aui reopened this May 17, 2013
@uc2dabing uc2dabing closed this May 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants