hzoo / babel-plugin-dedupe-string-literals Goto Github PK
View Code? Open in Web Editor NEWDedupe strings with new variable declarations.
Dedupe strings with new variable declarations.
I'm targeting ES6 and would like to use this together with babili
Understandably this tool is slow for large files such as https://raw.githubusercontent.com/mathiasbynens/unicode-8.0.0/15228776965be9ef1af995403b7d47386607318c/bidi-classes/index.js (over 6 MB).
One idea is to use a Map
rather than a plain object for the cache, which should result in faster lookups.
Map
usage isn’t transpiled away before publishing to npm. (Node.js v0.12.14+ supports Map
; personally I only care about Node.js v6 support since that’s what I use in my build environment.)When using dedupe-string-literals with webpack and babel-loader, we don't want strings passed to require.ensure()
or require()
to be deduped. Having another option that we could pass into this plugin would us specify strings that we do not want deduped.
plugins: [
['dedupe-string-literals', {
minimumStringLength: 2,
ignore: ['polyfills/x', 'modules/chunk']
}]
]
It's hardcoded for 2 cases
['a','a']
- ExpressionStatement
, ArrayExpression
in the body
var a = ['a','a']
- VariableDeclaration
, VariableDeclarator
, ArrayExpression
.
Needs to traverse parents to some level where a VariableDeclaration
is possible - basically the closest parent function scope?
It's only visiting arrays - doesn't have to be. but outside of the initial scope
Basically need to account for [['longstring', 'longstring'], ['longstring', 'longstring']]
, since currently it only dedupes per array.
https://github.com/hzoo/babel-plugin-dedupe-string-literals/blob/master/test/fixtures/example/expected.js as an example
cc @mathiasbynens - I think that's a blocker for the files you mentioned since I saw the nested arrays.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.