import { transformSync } from '@babel/core' ; import type { TransformOptions } from '@babel/core' ; import { ColocatedBabelPlugin } from '@cardstack/core/src/utils/babel' ; import { precompile } from '@glimmer/compiler' ; import HTMLBarsInlinePrecompile from 'babel-plugin-htmlbars-inline-precompile' ; import EmberModulesApiPolyfill from 'babel-plugin-ember-modules-api-polyfill' ; import TransformModulesAmd from '@babel/plugin-transform-modules-amd' ; import ClassPropertiesPlugin from '@babel/plugin-proposal-class-properties' ; /**
 * Transfrom a compiled card to a runtime card
 *
 * This is the final step of the dynamic building process.
 */ export default function dynamicCardTransform ( moduleURL , source ) { let out = transformSync ( source , babelConfig ( moduleURL ) ) ; return out ! . code ! ; } function babelConfig ( moduleURL ) { let ensureModuleApiPolyfill = true ; let plugins = [ [ HTMLBarsInlinePrecompile , { ensureModuleApiPolyfill , precompile , modules : { 'ember-cli-htmlbars' : 'hbs' , '@ember/template-compilation' : { export : 'precompileTemplate' , disableTemplateLiteral : true , shouldParseScope : true , isProduction : process . env . EMBER_ENV === 'production' , } , } , } , ] , ] ; if ( ensureModuleApiPolyfill ) { plugins . push ( [ EmberModulesApiPolyfill ] ) ; } plugins . push ( [ ColocatedBabelPlugin ] ) ; plugins . push ( [ ClassPropertiesPlugin ] ) ; plugins . push ( [ TransformModulesAmd , { noInterop : true , moduleId : moduleURL , } , ] ) ; return { configFile : false , babelrc : false , filenameRelative : moduleURL , plugins , } ; }