ember-cli / babel-plugin-htmlbars-inline-precompile

Babel plugin to replace tagged template strings with precompiled HTMLBars templates
9 stars 21 forks source link

[FEAT] Add `shouldParseScope`, `disableTemplateTag`, `disableFunctionCall` options #333

Closed pzuraq closed 3 years ago

pzuraq commented 3 years ago

This PR refactors modules to enable users to pass an options, with three options currently supported:

  1. shouldParseScope, which allows users to parse the scope parameter into a static format usable by the precompiler

    {
      modules: {
        'ember-cli-htmlbars': 'default',
        '@ember/template-compilation': {
          export: 'precompileTemplate',
          shouldParseScope: true,
        }
      }
    }

    When enabled, the scope parameter is parsed, and then turned into an array of the keys on the object. If a non-object is passed, or any of the keys or values are not references, then an error is thrown.

  2. disableTemplateTag, which disables using the precompile macro as a template tag. This should be used for precompileTemplate in ember-cli-htmlbars

  3. disableFunctionCall, which disables using the precompile macro as a function call. This should be used by experimental template import syntaxes.

This PR also refactors the way that imports statements are processed. They're now parsed in the beginning, in Program, ensuring that the parse step is only done once, and that we can build a list of all present imports in the file. This allows us to support more than one module at once.

rwjblue commented 3 years ago

Chatted with @pzuraq about the import ordering issue, and going to fix that in a follow on.