mirror of https://github.com/sveltejs/svelte
parent
dee8694e3b
commit
e796fefcee
@ -1,12 +0,0 @@
|
||||
import * as shared from '../../shared/index.js';
|
||||
|
||||
export const nameMap = new Map();
|
||||
export const sharedMap = new Map();
|
||||
|
||||
Object.keys(shared).forEach( key => {
|
||||
const value = shared[ key ]; // eslint-disable-line import/namespace
|
||||
if ( typeof value === 'function' ) {
|
||||
nameMap.set( value.name, key );
|
||||
}
|
||||
sharedMap.set( key, value.toString() );
|
||||
});
|
@ -0,0 +1,36 @@
|
||||
const fs = require( 'fs' );
|
||||
const path = require( 'path' );
|
||||
const acorn = require( 'acorn' );
|
||||
|
||||
const declarations = {};
|
||||
|
||||
fs.readdirSync( __dirname ).forEach( file => {
|
||||
if ( !/^[a-z]+\.js$/.test( file ) ) return;
|
||||
|
||||
const source = fs.readFileSync( path.join( __dirname, file ), 'utf-8' );
|
||||
const ast = acorn.parse( source, {
|
||||
ecmaVersion: 6,
|
||||
sourceType: 'module'
|
||||
});
|
||||
|
||||
ast.body.forEach( node => {
|
||||
if ( node.type !== 'ExportNamedDeclaration' ) return;
|
||||
|
||||
const { declaration } = node;
|
||||
if ( !declaration ) return;
|
||||
|
||||
const name = declaration.type === 'VariableDeclaration' ?
|
||||
declaration.declarations[0].id.name :
|
||||
declaration.id.name;
|
||||
|
||||
const value = declaration.type === 'VariableDeclaration' ?
|
||||
declaration.declarations[0].init :
|
||||
declaration;
|
||||
|
||||
const { start, end } = value;
|
||||
declarations[ name ] = source.slice( start, end );
|
||||
});
|
||||
});
|
||||
|
||||
fs.writeFileSync( 'src/generators/dom/shared.js', `// this file is auto-generated, do not edit it
|
||||
export default ${JSON.stringify( declarations, null, '\t' )};` );
|
Loading…
Reference in new issue