Created
August 24, 2015 16:42
-
-
Save hajimehoshi/63cd98b83fe36c039a2c to your computer and use it in GitHub Desktop.
tsc.js on browser
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
<!DOCTYPE html> | |
<script> | |
'use strict'; | |
var require = (function() { | |
class FS { | |
writeSync(fd, buffer, offset, toWrite) { | |
// TODO: Implement | |
console.log(buffer.str_); | |
} | |
existsSync(filename) { | |
// TODO: Implement | |
} | |
readFileSync(filename) { | |
// TODO: Implement | |
} | |
writeFileSync(filename) { | |
// TODO: Implement | |
} | |
readdirSync(path) { | |
throw 'not implemented'; | |
} | |
statSync(filename) { | |
throw 'not implemented'; | |
} | |
watchFile(filename, options, fileChanged) { | |
throw 'not implemented'; | |
} | |
unwatchFile(filename, fileChanged) { | |
throw 'not implemented'; | |
} | |
} | |
class Path { | |
resolve(path) { | |
return path; | |
} | |
} | |
class OS { | |
platform() { | |
return 'browser'; | |
} | |
get EOL() { | |
return '\n'; | |
} | |
} | |
return function(name) { | |
if (name === 'fs') { | |
return new FS(); | |
} | |
if (name === 'path') { | |
return new Path(); | |
} | |
if (name === 'os') { | |
return new OS(); | |
} | |
throw `not implemented: ${name}` | |
} | |
})(); | |
var module = { | |
exports: {}, | |
}; | |
var process = (function() { | |
class Process { | |
get argv() { | |
return []; | |
} | |
cwd() { | |
return '.'; | |
} | |
exit(code) { | |
// Do nothing | |
} | |
} | |
return new Process(); | |
})(); | |
var global = {}; | |
var __filename = 'test'; // TODO: What is the correct name? | |
class Buffer { | |
constructor(str, encoding) { | |
this.str_ = str; | |
if (encoding !== 'utf8') { | |
throw 'encoding must be utf8'; | |
} | |
} | |
get length() { | |
let n = 0; | |
for (let code of this.str_) { | |
if (code <= 0x7f) { | |
n++; | |
continue; | |
} | |
if (0x80 <= code && code <= 0x7ff) { | |
n += 2; | |
continue; | |
} | |
if (0x800 <= code && code <= 0xffff) { | |
n += 3; | |
continue; | |
} | |
n += 4; | |
} | |
return n; | |
} | |
} | |
</script> | |
<script src="./tsc.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment