remove `namespace` key from generated code

pull/390/head
Conduitry 8 years ago
parent cede99d68b
commit 77321f8356

@ -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
};
}

@ -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 ) {

@ -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 );
}
Loading…
Cancel
Save