Browse Source

remove unused code

contingency-plan
Rich-Harris 10 years ago
parent
commit
7c1d2bb8e6
  1. 7
      src/Module.js
  2. 4
      src/Statement.js
  3. 66
      src/ast/analyse.js

7
src/Module.js

@ -4,7 +4,6 @@ import { parse } from 'acorn';
import MagicString from 'magic-string';
import Statement from './Statement';
import walk from './ast/walk';
import analyse from './ast/analyse';
import { blank, keys } from './utils/object';
import { first, sequence } from './utils/promise';
import { isImportDeclaration, isExportDeclaration } from './utils/map-helpers';
@ -180,12 +179,10 @@ export default class Module {
this.statements.forEach( statement => {
if ( isImportDeclaration( statement ) ) this.addImport( statement );
else if ( isExportDeclaration( statement ) ) this.addExport( statement );
});
analyse( this.magicString, this );
statement.analyse();
// consolidate names that are defined/modified in this module
this.statements.forEach( statement => {
// consolidate names that are defined/modified in this module
keys( statement.defines ).forEach( name => {
this.definitions[ name ] = statement;
});

4
src/Statement.js

@ -24,10 +24,6 @@ export default class Statement {
this.isIncluded = false;
this.leadingComments = [];
this.trailingComment = null;
this.margin = [ 0, 0 ];
// some facts about this statement...
this.isImportDeclaration = node.type === 'ImportDeclaration';
this.isExportDeclaration = /^Export/.test( node.type );

66
src/ast/analyse.js

@ -1,66 +0,0 @@
export default function analyse ( magicString, module ) {
// first we need to generate comprehensive scope info
let previousStatement = null;
let commentIndex = 0;
module.statements.forEach( statement => {
const node = statement.node;
let trailing = !!previousStatement;
let previousComment;
// TODO surely this can be neater
// attach leading comment
do {
let comment = module.comments[ commentIndex ];
// prevent comments inside the previous statement being
// appended to it
if ( previousStatement ) {
while ( comment && comment.start < previousStatement.node.end ) {
commentIndex += 1;
comment = module.comments[ commentIndex ];
}
}
if ( !comment || ( comment.end > node.start ) ) break;
// attach any trailing comment to the previous statement
if ( trailing && !/\n/.test( module.source.slice( previousStatement.node.end, comment.start ) ) ) {
previousStatement.trailingComment = comment;
}
// then attach leading comments to this statement
else {
statement.leadingComments.push({
separator: previousComment ? magicString.slice( previousComment.end, comment.start ) : '\n',
comment
});
previousComment = comment;
}
commentIndex += 1;
trailing = false;
} while ( module.comments[ commentIndex ] );
// determine margin
const previousEnd = previousComment ?
previousComment.end :
previousStatement ?
( previousStatement.trailingComment || previousStatement.node ).end :
0;
//const start = ( statement.leadingComments[0] || node ).start;
const gap = magicString.original.slice( previousEnd, node.start );
const margin = gap.split( '\n' ).length;
if ( previousStatement ) previousStatement.margin[1] = margin;
statement.margin[0] = margin;
statement.analyse();
previousStatement = statement;
});
}
Loading…
Cancel
Save