1

Why not a parser in angularjs or regular expression replacing in vue? Which one is better? Is it OK to use "with" statement?

Konckoutjs

function createBindingsStringEvaluator(bindingsString, options) {
    // Build the source for a function that evaluates "expression"
    // For each scope variable, add an extra level of "with" nesting
    // Example result: with(sc1) { with(sc0) { return (expression) } }
    var rewrittenBindings = ko.expressionRewriting.preProcessBindings(bindingsString, options),
        functionBody = "with($context){with($data||{}){return{" + rewrittenBindings + "}}}";
    return new Function("$context", "$element", functionBody);
}

Angularjs

  var Parser = function(lexer, $filter, options) {
      this.lexer = lexer;
      this.$filter = $filter;
      this.options = options;
      this.ast = new AST(this.lexer);
      this.astCompiler = options.csp ? new ASTInterpreter(this.ast, $filter) :
      new ASTCompiler(this.ast, $filter);
  };
  ...

vue

  function compileExpFns (exp, needSet) {
      if (improperKeywordsRE.test(exp)) {
          process.env.NODE_ENV !== 'production' && _.warn(
          'Avoid using reserved keywords in expression: ' + exp)
      }
      // reset state
      saved.length = 0
      // save strings and object literal keys
      var body = exp
          .replace(saveRE, save)
          .replace(wsRE, '')
      // rewrite all paths
      // pad 1 space here becaue the regex matches 1 extra char
      body = (' ' + body)
          .replace(pathReplaceRE, rewrite)
          .replace(restoreRE, restore)
      ...
  }
YangChen
  • 213
  • 1
  • 2
  • 7

1 Answers1

0

According to JavaScript’s with statement and why it’s deprecated there is no safety and performance issues for JR's microtemplate because all the attributes only for output.

FYI Are there legitimate uses for JavaScript's “with” statement?

Community
  • 1
  • 1
unbuglee
  • 195
  • 1
  • 11