diff --git a/packages/ember-template-compiler/lib/system/compile-options.ts b/packages/ember-template-compiler/lib/system/compile-options.ts index 1f4c3e67964..87832571e09 100644 --- a/packages/ember-template-compiler/lib/system/compile-options.ts +++ b/packages/ember-template-compiler/lib/system/compile-options.ts @@ -82,11 +82,16 @@ interface LegacyPlugin { export type LegacyPluginClass = new (env: ASTPluginEnvironment) => LegacyPlugin; -function wrapLegacyPluginIfNeeded(_plugin: PluginFunc | LegacyPluginClass): PluginFunc { - let plugin = _plugin; - if (_plugin.prototype && _plugin.prototype.transform) { +function isLegacyPluginClass(plugin: PluginFunc | LegacyPluginClass): plugin is LegacyPluginClass { + return plugin.prototype && typeof plugin.prototype.transform === 'function'; +} + +function wrapLegacyPluginIfNeeded(plugin: PluginFunc | LegacyPluginClass): PluginFunc { + if (isLegacyPluginClass(plugin)) { + const Plugin = plugin; + deprecate( - 'Using class based template compilation plugins is deprecated, please update to the functional style', + `Using class based template compilation plugins is deprecated, please update to the functional style: ${Plugin.name}`, false, { id: 'template-compiler.registerPlugin', @@ -102,28 +107,29 @@ function wrapLegacyPluginIfNeeded(_plugin: PluginFunc | LegacyPluginClass): Plug let pluginInstantiated = false; return { - name: _plugin.constructor && _plugin.constructor.name, + name: plugin.name, visitor: { Program(node: AST.Program): AST.Node | void { if (!pluginInstantiated) { pluginInstantiated = true; - let plugin = new (_plugin as LegacyPluginClass)(env); + let instance = new Plugin(env); - plugin.syntax = env.syntax; + instance.syntax = env.syntax; - return plugin.transform(node); + return instance.transform(node); } }, }, }; }; - pluginFunc.__raw = _plugin as LegacyPluginClass; - plugin = pluginFunc; - } + pluginFunc.__raw = Plugin; - return plugin as PluginFunc; + return pluginFunc; + } else { + return plugin; + } } export function registerPlugin(type: string, _plugin: PluginFunc | LegacyPluginClass): void { diff --git a/packages/ember-template-compiler/tests/system/compile_options_test.js b/packages/ember-template-compiler/tests/system/compile_options_test.js index 921d3f2387a..1e2a036e923 100644 --- a/packages/ember-template-compiler/tests/system/compile_options_test.js +++ b/packages/ember-template-compiler/tests/system/compile_options_test.js @@ -124,7 +124,7 @@ moduleFor( class extends CustomPluginsTests { beforeEach() { expectDeprecation( - 'Using class based template compilation plugins is deprecated, please update to the functional style' + 'Using class based template compilation plugins is deprecated, please update to the functional style: LegacyCustomTransform' ); expectDeprecation( 'registerPlugin is deprecated, please pass plugins directly via `compile` and/or `precompile`.' @@ -141,7 +141,7 @@ moduleFor( ['@test custom registered plugins are deduplicated'](assert) { expectDeprecation( - 'Using class based template compilation plugins is deprecated, please update to the functional style' + 'Using class based template compilation plugins is deprecated, please update to the functional style: LegacyCustomTransform' ); expectDeprecation( 'registerPlugin is deprecated, please pass plugins directly via `compile` and/or `precompile`.' @@ -194,7 +194,7 @@ moduleFor( // override so that we can provide custom AST plugins to compile compile(templateString) { expectDeprecation( - 'Using class based template compilation plugins is deprecated, please update to the functional style' + 'Using class based template compilation plugins is deprecated, please update to the functional style: LegacyCustomTransform' ); return compile(templateString, { plugins: {