Created
May 6, 2019 19:23
-
-
Save jridgewell/9fec0c929c0acb8cb67ee0e5dd8a645e to your computer and use it in GitHub Desktop.
Demonstrating cross chunk code motion
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
import {test} from './base.js'; | |
import {inter} from './intermediate.js'; | |
inter(); | |
test('a'); |
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
import {test} from './base.js'; | |
import {inter} from './intermediate.js'; | |
inter(); | |
test('b'); |
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
const local = 'test'; | |
// I have to include some code to prevent cross method code motion. | |
export function crc32(str) { | |
const crcTable = new Array(256); | |
for (let i = 0; i < 256; i++) { | |
let c = i; | |
for (let j = 0; j < 8; j++) { | |
if (c & 1) { | |
c = (c >>> 1) ^ 0xEDB88320; | |
} else { | |
c = c >>> 1; | |
} | |
} | |
crcTable[i] = c; | |
} | |
// Shrink to 32 bits. | |
let crc = -1 >>> 0; | |
for (let i = 0; i < str.length; i++) { | |
const lookupIndex = (crc ^ str[i]) & 0xFF; | |
crc = (crc >>> 8) ^ crcTable[lookupIndex]; | |
} | |
return (crc ^ (-1)) >>> 0; | |
} | |
export function test(message) { | |
document.getElementById(local).innerText = crc32(message); | |
console.log(message); | |
} |
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
OPTS=( | |
"--language_in=ES6_STRICT" | |
"--language_out=ES5" | |
"--compilation_level=ADVANCED_OPTIMIZATIONS" | |
"--formatting=pretty_print" | |
"--js base.js" | |
"--chunk base:auto" | |
"--js intermediate.js" | |
"--chunk intermediate:1:base" | |
"--js a.js" | |
"--chunk a:1:intermediate" | |
"--js b.js" | |
"--chunk b:1:intermediate" | |
) | |
set -ex | |
java -jar compiler.jar $(echo ${OPTS[*]}) |
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
export function inter() { | |
console.log('inter'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment