@extjs/sencha-cmd-linux-32
Version:
Productivity and performance optimization tool for building applications with Sencha Ext JS and Sencha Touch.
116 lines (93 loc) • 2.95 kB
JavaScript
"use strict";
var Fashion = require('./export/Base.js'),
Base = Fashion.Base;
var Runtime = require('./Runtime.js');
var Preprocessor = require('./Preprocessor.js');
var Transpiler = require('./Transpiler.js');
var Parser = require('./parse/Parser.js');
var Scanner = require('./parse/Scanner.js');
class Context extends Base {
constructor(config) {
super(config);
this._fnMap = {};
this.runtime = this.runtime || new Runtime({
context: this
});
this.preprocessor = this.preprocessor || new Preprocessor({
runtime: this.runtime
});
this.transpiler = this.transpiler || new Transpiler({
preprocessor: this.preprocessor,
symbols: config && config.symbols
});
}
convert(ast, file) {
var node, parser, jsCode;
var transpiler = this.transpiler;
if (typeof ast === 'string') {
parser = new Parser();
node = parser.parse(ast, file);
} else {
node = ast;
}
this.preprocessor.preprocess(node);
jsCode = this.transpiler.transpile(node);
this.runtime.setCaches(this.transpiler);
this.lastVariables = transpiler.variables;
return jsCode;
}
getVariables() {
return this.lastVariables;
}
compile(jsCode) {
var me = this,
fn = this.runtime.compile(jsCode);
return me.func = function(rt, overrides, dyn) {
return fn(rt || me.runtime, overrides, dyn || me.dynamicsMap || me.preprocessor.getDynamicsMap());
};
}
getFunc() {
return this.func;
}
run(code) {
return this.runtime.run(code);
}
parseSelectors(selector) {
var fn = this._fnMap[selector],
runtime = this.runtime;
if (!fn) {
var parser = new Parser(),
transpiler = new Transpiler(),
ast, jsCode, parsedSelectors;
parser.scanner = new Scanner(selector);
parser.style = parser.scanner.style;
ast = parser.parseSelectors();
jsCode = transpiler.transpile(ast, true);
jsCode = "return " + jsCode + ";";
fn = runtime.createWrappedFn(jsCode);
this._fnMap[selector] = fn;
}
parsedSelectors = runtime.callWrappedFn(fn, {});
return parsedSelectors;
}
getConfig(name) {
return this[name];
}
setConfig(name, value) {
if (typeof name === 'string') {
var prev = this[name];
this[name] = value;
return prev;
}
Fashion.apply(this, name);
return null;
}
}
Fashion.apply(Context.prototype, {
runtime: undefined,
_fn: undefined,
preprocessor: undefined,
transpiler: undefined,
func: undefined
});
module.exports = Context;