UNPKG

ember-source

Version:

A JavaScript framework for creating ambitious web applications

110 lines (100 loc) 4.06 kB
import '../shared-chunks/fragment-Cc5k9Oy4.js'; import '../shared-chunks/debug-to-string-CFb7h0lY.js'; import '../@glimmer/wire-format/index.js'; import { p as precompile$1 } from '../shared-chunks/compiler-CNj62pww.js'; export { a as _preprocess } from '../shared-chunks/compiler-CNj62pww.js'; import '../@ember/debug/index.js'; import { STRICT_MODE_KEYWORDS, STRICT_MODE_TRANSFORMS, RESOLUTION_MODE_TRANSFORMS } from '../@ember/template-compiler/lib/plugins/index.js'; import '../shared-chunks/mandatory-setter-DHZe7-kW.js'; import { C as Cache } from '../shared-chunks/cache-qDyqAcpg.js'; import { assert } from '../@ember/debug/lib/assert.js'; export { b as _print } from '../shared-chunks/transform-resolutions-fXGQKGsL.js'; /* This diverges from `Ember.String.dasherize` so that`<XFoo />` can resolve to `x-foo`. `Ember.String.dasherize` would resolve it to `xfoo`.. */ const SIMPLE_DASHERIZE_REGEXP = /[A-Z]|::/g; const ALPHA = /[A-Za-z0-9]/; const COMPONENT_NAME_SIMPLE_DASHERIZE_CACHE = new Cache(1000, key => key.replace(SIMPLE_DASHERIZE_REGEXP, (char, index) => { if (char === '::') { return '/'; } if (index === 0 || !ALPHA.test(key[index - 1])) { return char.toLowerCase(); } return `-${char.toLowerCase()}`; })); let USER_PLUGINS = []; function malformedComponentLookup(string) { return string.indexOf('::') === -1 && string.indexOf(':') > -1; } function buildCompileOptions(_options) { let moduleName = _options.moduleName; let options = Object.assign({ meta: {}, isProduction: false, plugins: { ast: [] } }, _options, { moduleName, customizeComponentName(tagname) { (!(!malformedComponentLookup(tagname)) && assert(`You tried to invoke a component named <${tagname} /> in "${moduleName ?? '[NO MODULE]'}", but that is not a valid name for a component. Did you mean to use the "::" syntax for nested components?`, !malformedComponentLookup(tagname))); return COMPONENT_NAME_SIMPLE_DASHERIZE_CACHE.get(tagname); } }); if ('locals' in options && !options.locals) { // Glimmer's precompile options declare `locals` like: // locals?: string[] // but many in-use versions of babel-plugin-htmlbars-inline-precompile will // set locals to `null`. This used to work but only because glimmer was // ignoring locals for non-strict templates, and now it supports that case. delete options.locals; } // move `moduleName` into `meta` property if (options.moduleName) { let meta = options.meta; (!(meta) && assert('has meta', meta)); // We just set it meta.moduleName = options.moduleName; } if (options.strictMode) { options.keywords = STRICT_MODE_KEYWORDS; } return options; } function transformsFor(options) { return options.strictMode ? STRICT_MODE_TRANSFORMS : RESOLUTION_MODE_TRANSFORMS; } function compileOptions(_options = {}) { let options = buildCompileOptions(_options); let builtInPlugins = transformsFor(options); if (!_options.plugins) { options.plugins = { ast: [...USER_PLUGINS, ...builtInPlugins] }; } else { let potententialPugins = [...USER_PLUGINS, ...builtInPlugins]; (!(options.plugins) && assert('expected plugins', options.plugins)); let pluginsToAdd = potententialPugins.filter(plugin => { (!(options.plugins) && assert('expected plugins', options.plugins)); return options.plugins.ast.indexOf(plugin) === -1; }); options.plugins.ast = options.plugins.ast.concat(pluginsToAdd); } return options; } /** @module ember */ /** Uses HTMLBars `compile` function to process a string into a compiled template string. The returned string must be passed through `Ember.HTMLBars.template`. This is not present in production builds. @private @method precompile @param {String} templateString This is the string to be compiled by HTMLBars. */ function precompile(templateString, options = {}) { return precompile$1(templateString, compileOptions(options)); } export { buildCompileOptions as _buildCompileOptions, precompile };