Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support external language files in minified version of highlight.js (#…
…1888) * protect API during minification (supports external language files) * preprocess language api (apply core minification changes) * add test, optimize API_REPLACES
- Loading branch information
1 parent
dbe4ffa
commit f7184cc
Showing
5 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
let utility = require('../tools/utility'), | ||
bluebird = require('bluebird'), | ||
path = require('path'), | ||
readFile = bluebird.promisify(require('fs').readFile); | ||
|
||
describe("minification tools", () => { | ||
it("should replace API calls with minified names", () => { | ||
let content = "hljs.COMMENT(); hj.NUMBER_MODE == 0; a = hljs.endRe"; | ||
content.replace(utility.regex.replaces, utility.replaceClassNames).should.equal( | ||
"hljs.C(); hj.NM == 0; a = hljs.eR" | ||
); | ||
}); | ||
|
||
it("should replace API calls with minified names and protect declarations", () => { | ||
let content = "hj.NUMBER_MODE == 0; hljs.COMMENT = 1; a = hljs.endRe"; | ||
content.replace(utility.regex.replaces, utility.replaceClassNames).should.equal( | ||
"hj.NM == 0; hljs.C = hljs.COMMENT = 1; a = hljs.eR" | ||
); | ||
}); | ||
|
||
it("should NOT protect non-public member declarations", () => { | ||
let content = "hljs.endRe = 3;"; | ||
content.replace(utility.regex.replaces, utility.replaceClassNames).should.equal( | ||
"hljs.eR = 3;" | ||
); | ||
}); | ||
|
||
it("should assign API_REPLACES to the REPLACES dictionary in the highlight.js code", (done) => { | ||
readFile(path.join(__dirname, "../src/highlight.js"), 'utf-8').then(function(content) { | ||
"abc".should.containEql("bc"); | ||
content.should.not.containEql("var API_REPLACES = " + JSON.stringify(utility.REPLACES)); | ||
content.replace(utility.regex.apiReplacesFrom, utility.regex.apiReplacesTo) | ||
.should | ||
.containEql("var API_REPLACES = " + JSON.stringify(utility.REPLACES)); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters