- The solution must be 100% backward-compatible.
- In the far future, developers should be able to write Node programs and libraries without knowledge of the CommonJS module system.
- Module resolution rules should be reasonably compatible with the module resolution rules used by browsers.
- The ability to import a legacy package is important for adoption.
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
function dedent(callSite, ...args) { | |
function format(str) { | |
let size = -1; | |
return str.replace(/\n(\s+)/g, (m, m1) => { | |
if (size < 0) | |
size = m1.replace(/\t/g, " ").length; |
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 unwrapSymbol = Symbol(); | |
function unwrap(x) { | |
if (this == null) | |
return this; | |
let f = this[unwrapSymbol]; | |
if (typeof f !== "function") |
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
Observable.prototype[Symbol.asyncIterator] = async function*() { | |
function promiseCapability() { | |
x = {}; | |
x.promise = new Promise((a, b) => { | |
x.resolve = a; | |
x.reject = b; | |
}); | |
return x; | |
} |
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
hex_values = ['626f6f74', '72616365', '626c6168', '6f6f7073'] | |
packed_list = hex_values.map { |item| [item].pack('H*') }.sort().join() |
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
/* | |
A map class, implemented with private slots, which has the following properties: | |
- The presence of a mapping k => v in a SlotMap does not by itself make k or v reachable | |
- For each mapping k => v in a SlotMap m (whether m is reachable or not), if k is reachable then v is reachable | |
*/ | |
const DELETED = {}; |
The form @identifierName
is a symbol literal. Within any single module or script, two identitical symbol literals refer to the same symbol. Two identical symbol literals in separate modules or scripts refer to different symbols. A symbol literal may appear as a propery name or as a primary expression.
When a symbol literal appears as a primary expression, it is shorthand for this.@identifierName
.
When a symbol literal appears as a property name, the corresponding symbol is used as the property key during evaluation.
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
function once(el, event) { | |
return new Promise((resolve, reject) => { | |
const handler = e => { | |
resolve(e); | |
el.removeEventListener(event, handler); | |
}; | |
el.addEventListener(event, handler); | |
}); | |
}; |
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 { deprecated } from './macros/deprecated.js'; | |
// Using Rust-like syntax only to make it clear these | |
// are macros and not "decorators" | |
#[deprecated] | |
function dontUseMeAnymore() { | |
eval('You wrote a bad song, Petey!'); | |
} |
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
function* range(from, to) { | |
for (let i = from; i <= to; ++i) { | |
yield i; | |
} | |
} | |
function take(source, n) { | |
if (n <= 0) { | |
return Observable.from([]); | |
} |
NewerOlder