json-as 0.5.37 → 0.5.38
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/README.md +118 -116
- package/as-pect.asconfig.json +24 -24
- package/asconfig.json +18 -20
- package/assembly/__benches__/as-json.ts +30 -17
- package/assembly/__tests__/as-json.spec.ts +30 -22
- package/assembly/index.ts +1 -1
- package/assembly/src/chars.ts +1 -1
- package/assembly/src/json.ts +127 -103
- package/assembly/src/util.ts +40 -18
- package/assembly/test.ts +194 -13
- package/assembly/tsconfig.json +94 -1
- package/index.ts +1 -1
- package/package.json +1 -1
- package/transform/lib/hash.js +48 -50
- package/transform/lib/index.js +25 -7
- package/transform/lib/types.js +12 -12
- package/transform/package.json +36 -36
- package/transform/src/index.ts +54 -30
- package/transform/tsconfig.json +70 -70
- package/tsconfig.json +12 -12
- package/transform/src/hash.ts +0 -83
package/transform/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
ClassDeclaration,
|
|
3
3
|
FieldDeclaration,
|
|
4
4
|
Source,
|
|
5
|
-
Parser
|
|
5
|
+
Parser,
|
|
6
6
|
} from "assemblyscript/dist/assemblyscript";
|
|
7
7
|
import { toString, isStdlib } from "visitor-as/dist/utils.js";
|
|
8
8
|
import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js";
|
|
@@ -47,21 +47,32 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
47
47
|
parent: node.extendsType ? toString(node.extendsType) : "",
|
|
48
48
|
node: node,
|
|
49
49
|
encodeStmts: [],
|
|
50
|
-
setDataStmts: []
|
|
51
|
-
}
|
|
50
|
+
setDataStmts: [],
|
|
51
|
+
};
|
|
52
52
|
|
|
53
53
|
if (this.currentClass.parent.length > 0) {
|
|
54
|
-
const parentSchema = this.schemasList.find(
|
|
54
|
+
const parentSchema = this.schemasList.find(
|
|
55
|
+
(v) => v.name == this.currentClass.parent
|
|
56
|
+
);
|
|
55
57
|
if (parentSchema?.encodeStmts) {
|
|
56
58
|
parentSchema?.encodeStmts.push(parentSchema?.encodeStmts.pop() + ",");
|
|
57
59
|
this.currentClass.encodeStmts.push(...parentSchema?.encodeStmts);
|
|
58
60
|
} else {
|
|
59
|
-
console.error(
|
|
61
|
+
console.error(
|
|
62
|
+
"Class extends " +
|
|
63
|
+
this.currentClass.parent +
|
|
64
|
+
", but parent class not found. Maybe add the @json decorator over parent class?"
|
|
65
|
+
);
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
const parentSchema = this.schemasList.find(
|
|
64
|
-
|
|
69
|
+
const parentSchema = this.schemasList.find(
|
|
70
|
+
(v) => v.name == this.currentClass.parent
|
|
71
|
+
);
|
|
72
|
+
const members = [
|
|
73
|
+
...node.members,
|
|
74
|
+
...(parentSchema ? parentSchema.node.members : []),
|
|
75
|
+
];
|
|
65
76
|
|
|
66
77
|
for (const mem of members) {
|
|
67
78
|
if (mem.type && mem.type.name && mem.type.name.identifier.text) {
|
|
@@ -72,13 +83,26 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
72
83
|
|
|
73
84
|
// @ts-ignore
|
|
74
85
|
let type = toString(member.type);
|
|
75
|
-
|
|
86
|
+
|
|
76
87
|
const name = member.name.text;
|
|
77
88
|
this.currentClass.keys.push(name);
|
|
78
89
|
// @ts-ignore
|
|
79
90
|
this.currentClass.types.push(type);
|
|
80
91
|
// @ts-ignore
|
|
81
|
-
if (
|
|
92
|
+
if (
|
|
93
|
+
[
|
|
94
|
+
"u8",
|
|
95
|
+
"i8",
|
|
96
|
+
"u16",
|
|
97
|
+
"i16",
|
|
98
|
+
"u32",
|
|
99
|
+
"i32",
|
|
100
|
+
"f32",
|
|
101
|
+
"u64",
|
|
102
|
+
"i64",
|
|
103
|
+
"f64",
|
|
104
|
+
].includes(type.toLowerCase())
|
|
105
|
+
) {
|
|
82
106
|
this.currentClass.encodeStmts.push(
|
|
83
107
|
`"${name}":\${this.${name}.toString()},`
|
|
84
108
|
);
|
|
@@ -101,11 +125,12 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
101
125
|
let serializeFunc = "";
|
|
102
126
|
|
|
103
127
|
if (this.currentClass.encodeStmts.length > 0) {
|
|
104
|
-
const stmt =
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
128
|
+
const stmt =
|
|
129
|
+
this.currentClass.encodeStmts[
|
|
130
|
+
this.currentClass.encodeStmts.length - 1
|
|
131
|
+
]!;
|
|
132
|
+
this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1] =
|
|
133
|
+
stmt!.slice(0, stmt.length - 1);
|
|
109
134
|
serializeFunc = `
|
|
110
135
|
@inline
|
|
111
136
|
__JSON_Serialize(): string {
|
|
@@ -134,10 +159,7 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
134
159
|
const serializeMethod = SimpleParser.parseClassMember(serializeFunc, node);
|
|
135
160
|
node.members.push(serializeMethod);
|
|
136
161
|
|
|
137
|
-
const setDataMethod = SimpleParser.parseClassMember(
|
|
138
|
-
setKeyFunc,
|
|
139
|
-
node
|
|
140
|
-
);
|
|
162
|
+
const setDataMethod = SimpleParser.parseClassMember(setKeyFunc, node);
|
|
141
163
|
node.members.push(setDataMethod);
|
|
142
164
|
|
|
143
165
|
this.schemasList.push(this.currentClass);
|
|
@@ -154,17 +176,19 @@ export default class Transformer extends Transform {
|
|
|
154
176
|
const transformer = new AsJSONTransform();
|
|
155
177
|
|
|
156
178
|
// Sort the sources so that user scripts are visited last
|
|
157
|
-
const sources = parser.sources
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
179
|
+
const sources = parser.sources
|
|
180
|
+
.filter((source) => !isStdlib(source))
|
|
181
|
+
.sort((_a, _b) => {
|
|
182
|
+
const a = _a.internalPath;
|
|
183
|
+
const b = _b.internalPath;
|
|
184
|
+
if (a[0] === "~" && b[0] !== "~") {
|
|
185
|
+
return -1;
|
|
186
|
+
} else if (a[0] !== "~" && b[0] === "~") {
|
|
187
|
+
return 1;
|
|
188
|
+
} else {
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
168
192
|
|
|
169
193
|
// Loop over every source
|
|
170
194
|
for (const source of sources) {
|
|
@@ -174,4 +198,4 @@ export default class Transformer extends Transform {
|
|
|
174
198
|
}
|
|
175
199
|
}
|
|
176
200
|
}
|
|
177
|
-
}
|
|
201
|
+
}
|
package/transform/tsconfig.json
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Basic Options */
|
|
6
|
-
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
-
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
|
8
|
-
"module": "es6" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
|
9
|
-
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
|
-
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
-
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
-
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
|
13
|
-
"declaration": false /* Generates corresponding '.d.ts' file. */,
|
|
14
|
-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
-
"sourceMap": false /* Generates corresponding '.map' file. */,
|
|
16
|
-
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
-
"outDir": "./lib" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
|
18
|
-
// "composite": true, /* Enable project compilation */
|
|
19
|
-
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
20
|
-
// "removeComments": true, /* Do not emit comments to output. */
|
|
21
|
-
// "noEmit": true, /* Do not emit outputs. */
|
|
22
|
-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
23
|
-
"downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
|
|
24
|
-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
25
|
-
|
|
26
|
-
/* Strict Type-Checking Options */
|
|
27
|
-
"strict": true /* Enable all strict type-checking options. */,
|
|
28
|
-
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'Unknown' type. */,
|
|
29
|
-
"strictNullChecks": true /* Enable strict null checks. */,
|
|
30
|
-
"strictFunctionTypes": true /* Enable strict checking of function types. */,
|
|
31
|
-
"strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */,
|
|
32
|
-
"strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
|
|
33
|
-
"noImplicitThis": true /* Raise error on 'this' expressions with an implied 'Unknown' type. */,
|
|
34
|
-
"alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
|
|
35
|
-
|
|
36
|
-
/* Additional Checks */
|
|
37
|
-
"noUnusedLocals": true /* Report errors on unused locals. */,
|
|
38
|
-
"noUnusedParameters": true /* Report errors on unused parameters. */,
|
|
39
|
-
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
|
40
|
-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
41
|
-
"noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
|
|
42
|
-
"noPropertyAccessFromIndexSignature": true /* Require undeclared properties from index signatures to use element accesses. */,
|
|
43
|
-
|
|
44
|
-
/* Module Resolution Options */
|
|
45
|
-
"moduleResolution": "node"
|
|
46
|
-
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
47
|
-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
48
|
-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
49
|
-
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
50
|
-
// "types": [], /* Type declaration files to be included in compilation. */
|
|
51
|
-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
52
|
-
"esModuleInterop": false /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
|
53
|
-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
54
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
55
|
-
|
|
56
|
-
/* Source Map Options */
|
|
57
|
-
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
58
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
59
|
-
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
60
|
-
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
61
|
-
|
|
62
|
-
/* Experimental Options */
|
|
63
|
-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
64
|
-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
65
|
-
|
|
66
|
-
/* Advanced Options */
|
|
67
|
-
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
|
68
|
-
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Basic Options */
|
|
6
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
+
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
|
8
|
+
"module": "es6" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
|
9
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
|
13
|
+
"declaration": false /* Generates corresponding '.d.ts' file. */,
|
|
14
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
+
"sourceMap": false /* Generates corresponding '.map' file. */,
|
|
16
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
+
"outDir": "./lib" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
|
18
|
+
// "composite": true, /* Enable project compilation */
|
|
19
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
20
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
21
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
22
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
23
|
+
"downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
|
|
24
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
25
|
+
|
|
26
|
+
/* Strict Type-Checking Options */
|
|
27
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
28
|
+
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'Unknown' type. */,
|
|
29
|
+
"strictNullChecks": true /* Enable strict null checks. */,
|
|
30
|
+
"strictFunctionTypes": true /* Enable strict checking of function types. */,
|
|
31
|
+
"strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */,
|
|
32
|
+
"strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
|
|
33
|
+
"noImplicitThis": true /* Raise error on 'this' expressions with an implied 'Unknown' type. */,
|
|
34
|
+
"alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
|
|
35
|
+
|
|
36
|
+
/* Additional Checks */
|
|
37
|
+
"noUnusedLocals": true /* Report errors on unused locals. */,
|
|
38
|
+
"noUnusedParameters": true /* Report errors on unused parameters. */,
|
|
39
|
+
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
|
40
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
41
|
+
"noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
|
|
42
|
+
"noPropertyAccessFromIndexSignature": true /* Require undeclared properties from index signatures to use element accesses. */,
|
|
43
|
+
|
|
44
|
+
/* Module Resolution Options */
|
|
45
|
+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
|
|
46
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
47
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
48
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
49
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
50
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
51
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
52
|
+
"esModuleInterop": false /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
|
53
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
54
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
55
|
+
|
|
56
|
+
/* Source Map Options */
|
|
57
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
58
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
59
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
60
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
61
|
+
|
|
62
|
+
/* Experimental Options */
|
|
63
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
64
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
65
|
+
|
|
66
|
+
/* Advanced Options */
|
|
67
|
+
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
|
68
|
+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
69
|
+
}
|
|
70
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
12
|
|
|
13
13
|
/* Language and Environment */
|
|
14
|
-
"target": "es2016"
|
|
14
|
+
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
15
15
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
16
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
"experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
18
|
+
"emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
19
|
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
20
|
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
21
|
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
26
|
|
|
27
27
|
/* Modules */
|
|
28
|
-
"module": "commonjs"
|
|
28
|
+
"module": "commonjs" /* Specify what module code is generated. */,
|
|
29
29
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
30
|
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
31
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
@@ -71,22 +71,22 @@
|
|
|
71
71
|
/* Interop Constraints */
|
|
72
72
|
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
73
73
|
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
74
|
-
"esModuleInterop": true
|
|
74
|
+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
75
75
|
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
76
|
-
"forceConsistentCasingInFileNames": true
|
|
76
|
+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
77
77
|
|
|
78
78
|
/* Type Checking */
|
|
79
|
-
"strict": true
|
|
79
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
80
80
|
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
81
|
-
|
|
81
|
+
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
82
82
|
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
83
83
|
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
84
84
|
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
85
85
|
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
86
86
|
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
"alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
88
|
+
"noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
89
|
+
"noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
90
90
|
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
91
91
|
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
92
92
|
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
@@ -98,6 +98,6 @@
|
|
|
98
98
|
|
|
99
99
|
/* Completeness */
|
|
100
100
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
101
|
-
"skipLibCheck": true
|
|
101
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
102
102
|
}
|
|
103
103
|
}
|
package/transform/src/hash.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// XXHash 32-bit as a starting point, see: https://cyan4973.github.io/xxHash
|
|
2
|
-
|
|
3
|
-
// primes
|
|
4
|
-
// @ts-ignore: decorator
|
|
5
|
-
const XXH32_P1: number = 2654435761;
|
|
6
|
-
// @ts-ignore: decorator
|
|
7
|
-
const XXH32_P2: number = 2246822519;
|
|
8
|
-
// @ts-ignore: decorator
|
|
9
|
-
const XXH32_P3: number = 3266489917;
|
|
10
|
-
// @ts-ignore: decorator
|
|
11
|
-
const XXH32_P4: number = 668265263;
|
|
12
|
-
// @ts-ignore: decorator
|
|
13
|
-
const XXH32_P5: number = 374761393;
|
|
14
|
-
// @ts-ignore: decorator
|
|
15
|
-
const XXH32_SEED: number = 0;
|
|
16
|
-
|
|
17
|
-
function hash32(key: number, len: number = 4): number {
|
|
18
|
-
let h: number = XXH32_SEED + XXH32_P5 + len;
|
|
19
|
-
h += key * XXH32_P3;
|
|
20
|
-
h = rotl(h, 17) * XXH32_P4;
|
|
21
|
-
h ^= h >> 15;
|
|
22
|
-
h *= XXH32_P2;
|
|
23
|
-
h ^= h >> 13;
|
|
24
|
-
h *= XXH32_P3;
|
|
25
|
-
h ^= h >> 16;
|
|
26
|
-
return h;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function rotl(x: number, r: number): number {
|
|
30
|
-
return (x << r) | (x >>> (32 - r));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function mix(h: number, key: number): number {
|
|
34
|
-
return rotl(h + key * XXH32_P2, 13) * XXH32_P1;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function hashStr(key: string): number {
|
|
38
|
-
if (key == null) return XXH32_SEED;
|
|
39
|
-
|
|
40
|
-
let h: number = key.length;
|
|
41
|
-
let len: number = h;
|
|
42
|
-
let pos = 0;
|
|
43
|
-
|
|
44
|
-
if (len >= 16) {
|
|
45
|
-
let s1 = XXH32_SEED + XXH32_P1 + XXH32_P2;
|
|
46
|
-
let s2 = XXH32_SEED + XXH32_P2;
|
|
47
|
-
let s3 = XXH32_SEED;
|
|
48
|
-
let s4 = XXH32_SEED - XXH32_P1;
|
|
49
|
-
|
|
50
|
-
let end = len + pos - 16;
|
|
51
|
-
while (pos <= end) {
|
|
52
|
-
s1 = mix(s1, key.charCodeAt(pos));
|
|
53
|
-
s2 = mix(s2, key.charCodeAt(pos + 1));
|
|
54
|
-
s3 = mix(s3, key.charCodeAt(pos + 2));
|
|
55
|
-
s4 = mix(s4, load<number>(pos, 12));
|
|
56
|
-
pos += 16;
|
|
57
|
-
}
|
|
58
|
-
h += rotl(s1, 1) + rotl(s2, 7) + rotl(s3, 12) + rotl(s4, 18);
|
|
59
|
-
} else {
|
|
60
|
-
h += XXH32_SEED + XXH32_P5;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let end = changetype<number>(key) + len - 4;
|
|
64
|
-
while (pos <= end) {
|
|
65
|
-
h += load<number>(pos) * XXH32_P3;
|
|
66
|
-
h = rotl(h, 17) * XXH32_P4;
|
|
67
|
-
pos += 4;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
end = changetype<number>(key) + len;
|
|
71
|
-
while (pos < end) {
|
|
72
|
-
h += <number>load<u8>(pos) * XXH32_P5;
|
|
73
|
-
h = rotl(h, 11) * XXH32_P1;
|
|
74
|
-
pos++;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
h ^= h >> 15;
|
|
78
|
-
h *= XXH32_P2;
|
|
79
|
-
h ^= h >> 13;
|
|
80
|
-
h *= XXH32_P3;
|
|
81
|
-
h ^= h >> 16;
|
|
82
|
-
return h;
|
|
83
|
-
}
|