diff --git a/src/generators/Generator.js b/src/generators/Generator.js index f0571d96c1..469b271f85 100644 --- a/src/generators/Generator.js +++ b/src/generators/Generator.js @@ -232,6 +232,7 @@ export default class Generator { const imports = this.imports; const computations = []; + let defaultExport = null; const templateProperties = {}; if ( js ) { @@ -251,7 +252,7 @@ export default class Generator { } } - const defaultExport = js.content.body.find( node => node.type === 'ExportDefaultDeclaration' ); + defaultExport = js.content.body.find( node => node.type === 'ExportDefaultDeclaration' ); if ( defaultExport ) { const finalNode = js.content.body[ js.content.body.length - 1 ]; @@ -319,6 +320,7 @@ export default class Generator { return { computations, + defaultExport, templateProperties }; } diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index e066a6c48e..0a4036c355 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -3,6 +3,7 @@ import getBuilders from './utils/getBuilders.js'; import CodeBuilder from '../../utils/CodeBuilder.js'; import namespaces from '../../utils/namespaces.js'; import processCss from '../shared/processCss.js'; +import removeObjectKey from '../../utils/removeObjectKey.js'; import visitors from './visitors/index.js'; import Generator from '../Generator.js'; import * as shared from '../../shared/index.js'; @@ -162,7 +163,7 @@ export default function dom ( parsed, source, options, names ) { const generator = new DomGenerator( parsed, source, name, names, visitors, options ); - const { computations, templateProperties } = generator.parseJs(); + const { computations, defaultExport, templateProperties } = generator.parseJs(); // Remove these after version 2 if ( templateProperties.onrender ) { @@ -188,7 +189,7 @@ export default function dom ( parsed, source, options, names ) { const ns = templateProperties.namespace.value.value; namespace = namespaces[ ns ] || ns; - // TODO remove the namespace property from the generated code, it's unused past this point + removeObjectKey( generator.code, defaultExport.declaration, 'namespace' ); } if ( templateProperties.components ) { diff --git a/src/utils/removeObjectKey.js b/src/utils/removeObjectKey.js new file mode 100644 index 0000000000..7399a6a2bb --- /dev/null +++ b/src/utils/removeObjectKey.js @@ -0,0 +1,9 @@ +export default function removeObjectKey ( code, parsed, key ) { + if ( parsed.type !== 'ObjectExpression' ) return; + const properties = parsed.properties; + const index = properties.findIndex( property => property.key.type === 'Identifier' && property.key.name === key ); + if ( index === -1 ) return; + const a = properties[ index ].start; + const b = index < properties.length - 1 ? properties[ index + 1 ].start : properties[ index ].end; + code.remove( a, b ); +}