mirror of https://github.com/lukechilds/rollup.git
10 changed files with 74 additions and 44 deletions
@ -1,16 +1,34 @@ |
|||
const validProp = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; |
|||
|
|||
export default function flatten ( node ) { |
|||
const keypath = node.toString(); // TODO is this the best way?
|
|||
const parts = []; |
|||
|
|||
while ( node.type === 'MemberExpression' ) { |
|||
if ( node.computed ) return null; |
|||
parts.unshift( node.property.name ); |
|||
if ( node.computed ) { |
|||
if ( node.type !== 'Literal' || typeof node.value !== 'string' || !validProp.test( node.value ) ) { |
|||
return null; |
|||
} |
|||
} |
|||
parts.unshift( node.property ); |
|||
|
|||
node = node.object; |
|||
} |
|||
|
|||
if ( node.type !== 'Identifier' ) return null; |
|||
const root = node; |
|||
let name; |
|||
|
|||
if ( root.type === 'Identifier' ) { |
|||
name = root.name; |
|||
} else if ( root.type === 'ThisExpression' ) { |
|||
name = 'this'; |
|||
} else if ( root.type === 'Super' ) { |
|||
name = 'super'; |
|||
} else { |
|||
return null; |
|||
} |
|||
|
|||
const name = node.name; |
|||
parts.unshift( name ); |
|||
parts.unshift( root ); |
|||
|
|||
return { name, keypath: parts.join( '.' ) }; |
|||
return { root, name, parts, keypath }; |
|||
} |
|||
|
@ -1,3 +1,4 @@ |
|||
module.exports = { |
|||
solo: true, |
|||
description: 'statements that modify definitions within unused functions are excluded' |
|||
}; |
|||
|
@ -1,4 +1,3 @@ |
|||
module.exports = { |
|||
solo: true, |
|||
description: 'it does static lookup optimization of internal namespaces' |
|||
}; |
|||
|
Loading…
Reference in new issue