UNPKG

can

Version:

MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.

74 lines (73 loc) 2.44 kB
/*! * CanJS - 2.3.34 * http://canjs.com/ * Copyright (c) 2018 Bitovi * Mon, 30 Apr 2018 20:56:51 GMT * Licensed MIT */ /*can@2.3.34#view/stache/intermediate_and_imports*/ define([ 'can/view/mustache_core', 'can/view/parser', 'can/view/import' ], function (mustacheCore, parser) { return function (source) { var template = mustacheCore.cleanLineEndings(source); var imports = [], dynamicImports = [], ases = {}, inImport = false, inFrom = false, inAs = false, isUnary = false, currentAs = '', currentFrom = ''; var intermediate = parser(template, { start: function (tagName, unary) { isUnary = unary; if (tagName === 'can-import') { inImport = true; } else if (inImport) { inImport = false; } }, attrStart: function (attrName) { if (attrName === 'from') { inFrom = true; } else if (attrName === 'as' || attrName === 'export-as') { inAs = true; } }, attrEnd: function (attrName) { if (attrName === 'from') { inFrom = false; } else if (attrName === 'as' || attrName === 'export-as') { inAs = false; } }, attrValue: function (value) { if (inFrom && inImport) { imports.push(value); if (!isUnary) { dynamicImports.push(value); } currentFrom = value; } else if (inAs && inImport) { currentAs = value; } }, end: function (tagName) { if (tagName === 'can-import') { if (currentAs) { ases[currentAs] = currentFrom; currentAs = ''; } } }, close: function (tagName) { if (tagName === 'can-import') { imports.pop(); } } }, true); return { intermediate: intermediate, imports: imports, dynamicImports: dynamicImports, ases: ases, exports: ases }; }; });