@chevrotain/utils 10.1.1 → 10.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/api.ts +3 -0
- package/src/print.ts +14 -0
- package/src/timer.ts +7 -0
- package/src/to-fast-properties.ts +23 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chevrotain/utils",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.2",
|
|
4
4
|
"description": "common utilities",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"bugs": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"typings": "lib/src/api.d.ts",
|
|
14
14
|
"main": "lib/src/api.js",
|
|
15
15
|
"files": [
|
|
16
|
+
"src/**/*.ts",
|
|
16
17
|
"lib/src/**/*.js",
|
|
17
18
|
"lib/src/**/*.d.ts",
|
|
18
19
|
"lib/src/**/*.js.map",
|
|
@@ -36,5 +37,5 @@
|
|
|
36
37
|
"publishConfig": {
|
|
37
38
|
"access": "public"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "a9669e27213c0cac9ce59d890d331dc27f20190d"
|
|
40
41
|
}
|
package/src/api.ts
ADDED
package/src/print.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function PRINT_ERROR(msg: string) {
|
|
2
|
+
/* istanbul ignore else - can't override global.console in node.js */
|
|
3
|
+
if (console && console.error) {
|
|
4
|
+
console.error(`Error: ${msg}`)
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function PRINT_WARNING(msg: string) {
|
|
9
|
+
/* istanbul ignore else - can't override global.console in node.js*/
|
|
10
|
+
if (console && console.warn) {
|
|
11
|
+
// TODO: modify docs accordingly
|
|
12
|
+
console.warn(`Warning: ${msg}`)
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/timer.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// based on: https://github.com/petkaantonov/bluebird/blob/b97c0d2d487e8c5076e8bd897e0dcd4622d31846/src/util.js#L201-L216
|
|
2
|
+
export function toFastProperties(toBecomeFast: any) {
|
|
3
|
+
function FakeConstructor() {}
|
|
4
|
+
|
|
5
|
+
// If our object is used as a constructor it would receive
|
|
6
|
+
FakeConstructor.prototype = toBecomeFast
|
|
7
|
+
const fakeInstance = new (FakeConstructor as any)()
|
|
8
|
+
|
|
9
|
+
function fakeAccess() {
|
|
10
|
+
return typeof fakeInstance.bar
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// help V8 understand this is a "real" prototype by actually using
|
|
14
|
+
// the fake instance.
|
|
15
|
+
fakeAccess()
|
|
16
|
+
fakeAccess()
|
|
17
|
+
|
|
18
|
+
return toBecomeFast
|
|
19
|
+
// Eval prevents optimization of this method (even though this is dead code)
|
|
20
|
+
/* istanbul ignore next */
|
|
21
|
+
// tslint:disable-next-line
|
|
22
|
+
eval(toBecomeFast)
|
|
23
|
+
}
|