(
template,
options,
vm
)
| 9003 | } |
| 9004 | |
| 9005 | function compileToFunctions ( |
| 9006 | template, |
| 9007 | options, |
| 9008 | vm |
| 9009 | ) { |
| 9010 | options = options || {}; |
| 9011 | |
| 9012 | /* istanbul ignore if */ |
| 9013 | { |
| 9014 | // detect possible CSP restriction |
| 9015 | try { |
| 9016 | new Function('return 1'); |
| 9017 | } catch (e) { |
| 9018 | if (e.toString().match(/unsafe-eval|CSP/)) { |
| 9019 | warn( |
| 9020 | 'It seems you are using the standalone build of Vue.js in an ' + |
| 9021 | 'environment with Content Security Policy that prohibits unsafe-eval. ' + |
| 9022 | 'The template compiler cannot work in this environment. Consider ' + |
| 9023 | 'relaxing the policy to allow unsafe-eval or pre-compiling your ' + |
| 9024 | 'templates into render functions.' |
| 9025 | ); |
| 9026 | } |
| 9027 | } |
| 9028 | } |
| 9029 | |
| 9030 | // check cache |
| 9031 | var key = options.delimiters |
| 9032 | ? String(options.delimiters) + template |
| 9033 | : template; |
| 9034 | if (functionCompileCache[key]) { |
| 9035 | return functionCompileCache[key] |
| 9036 | } |
| 9037 | |
| 9038 | // compile |
| 9039 | var compiled = compile(template, options); |
| 9040 | |
| 9041 | // check compilation errors/tips |
| 9042 | { |
| 9043 | if (compiled.errors && compiled.errors.length) { |
| 9044 | warn( |
| 9045 | "Error compiling template:\n\n" + template + "\n\n" + |
| 9046 | compiled.errors.map(function (e) { return ("- " + e); }).join('\n') + '\n', |
| 9047 | vm |
| 9048 | ); |
| 9049 | } |
| 9050 | if (compiled.tips && compiled.tips.length) { |
| 9051 | compiled.tips.forEach(function (msg) { return tip(msg, vm); }); |
| 9052 | } |
| 9053 | } |
| 9054 | |
| 9055 | // turn code into functions |
| 9056 | var res = {}; |
| 9057 | var fnGenErrors = []; |
| 9058 | res.render = makeFunction(compiled.render, fnGenErrors); |
| 9059 | var l = compiled.staticRenderFns.length; |
| 9060 | res.staticRenderFns = new Array(l); |
| 9061 | for (var i = 0; i < l; i++) { |
| 9062 | res.staticRenderFns[i] = makeFunction(compiled.staticRenderFns[i], fnGenErrors); |
no test coverage detected