Skip to content

Commit b4b4d40

Browse files
authored
update dependencies (#123)
1 parent 414439f commit b4b4d40

File tree

5 files changed

+52
-33
lines changed

5 files changed

+52
-33
lines changed

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@
2929
},
3030
"license": "MIT",
3131
"devDependencies": {
32-
"@microsoft/api-extractor": "^7.39.0",
32+
"@microsoft/api-extractor": "^7.47.0",
3333
"@rollup/plugin-alias": "^5.1.0",
3434
"@rollup/plugin-node-resolve": "^15.2.3",
35-
"@rollup/plugin-replace": "^5.0.5",
35+
"@rollup/plugin-replace": "^5.0.7",
3636
"@rollup/plugin-terser": "^0.4.4",
37-
"@rollup/plugin-typescript": "^11.1.5",
37+
"@rollup/plugin-typescript": "^11.1.6",
3838
"@tybys/cross-zip": "^3.1.0",
3939
"@tybys/ts-transform-pure-class": "^0.1.1",
4040
"@tybys/tsapi": "^0.6.0",
4141
"@types/fs-extra": "^11.0.4",
42-
"@types/node": "^20.10.6",
43-
"@typescript-eslint/eslint-plugin": "^6.16.0",
44-
"@typescript-eslint/parser": "^6.16.0",
45-
"eslint": "^8.56.0",
46-
"eslint-config-standard-with-typescript": "^43.0.0",
42+
"@types/node": "^20.14.10",
43+
"@typescript-eslint/eslint-plugin": "^6.21.0",
44+
"@typescript-eslint/parser": "^6.21.0",
45+
"eslint": "^8.57.0",
46+
"eslint-config-standard-with-typescript": "^43.0.1",
4747
"eslint-plugin-import": "^2.29.1",
48-
"eslint-plugin-n": "^16.6.0",
49-
"eslint-plugin-promise": "^6.1.1",
48+
"eslint-plugin-n": "^16.6.2",
49+
"eslint-plugin-promise": "^6.4.0",
5050
"fs-extra": "^11.2.0",
51-
"glob": "^10.3.10",
52-
"rollup": "^4.9.1",
53-
"typescript": "~5.3.3"
51+
"glob": "^10.4.5",
52+
"rollup": "^4.18.1",
53+
"typescript": "~5.4.2"
5454
},
5555
"workspaces": [
5656
"packages/ts-transform-macro",

packages/test/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"description": "emnapi test",
66
"main": "index.js",
77
"devDependencies": {
8-
"@tybys/wasm-util": "^0.8.0",
9-
"chalk": "^4.1.1",
10-
"cmake-js": "^7.1.1",
8+
"@tybys/wasm-util": "^0.8.3",
9+
"chalk": "^4.1.2",
10+
"cmake-js": "^7.3.0",
1111
"cross-env": "^7.0.3",
12-
"glob": "^7.2.0",
13-
"memfs-browser": "^3.4.13000",
14-
"node-addon-api": "7.0.0",
15-
"why-is-node-running": "^2.2.2"
12+
"glob": "^7.2.3",
13+
"memfs-browser": "^3.5.10302",
14+
"node-addon-api": "8.1.0",
15+
"why-is-node-running": "^2.3.0"
1616
},
1717
"scripts": {
1818
"rebuild": "cross-env UV_THREADPOOL_SIZE=2 node ./script/build-emscripten.js Debug",

packages/ts-transform-emscripten-parse-tools/src/index.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
VisitResult,
2020
Statement
2121
} from 'typescript'
22+
import { cloneNode, type CloneNodeOptions } from 'ts-clone-node'
2223

2324
import ts = require('typescript')
2425
import { join, resolve } from 'path'
@@ -104,10 +105,26 @@ function getDataViewSetMethod (defines: Record<string, any>, type: Type): string
104105
}
105106
}
106107

108+
function parseExpression (input: string, factory?: NodeFactory): Expression {
109+
const expression: Expression = (ts.createSourceFile('', input, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS).statements[0] as ExpressionStatement).expression
110+
const cloneOptions: Partial<CloneNodeOptions<Expression>> = {
111+
typescript: ts,
112+
factory,
113+
setOriginalNodes: true,
114+
setParents: true,
115+
preserveComments: true,
116+
preserveSymbols: true
117+
}
118+
return cloneNode(expression, cloneOptions)
119+
}
120+
107121
function byteOffsetParameter (factory: NodeFactory, defines: Record<string, any>, param: Expression): NumericLiteral | Expression {
108-
if (ts.isNumericLiteral(param) || ts.isStringLiteral(param)) {
122+
if (ts.isNumericLiteral(param)) {
109123
return factory.createNumericLiteral(param.text)
110124
}
125+
if (ts.isStringLiteral(param)) {
126+
return parseExpression(param.text, factory)
127+
}
111128
if (ts.isIdentifier(param)) {
112129
if (param.text === 'POINTER_SIZE') {
113130
return factory.createNumericLiteral(defines.MEMORY64 ? 8 : 4)
@@ -120,7 +137,7 @@ function byteOffsetParameter (factory: NodeFactory, defines: Record<string, any>
120137
if (!ts.isStringLiteral(left)) throw new Error('left must be string literal')
121138
if (!ts.isIdentifier(right)) throw new Error('right must be identifier')
122139
if (right.text !== 'POINTER_SIZE') throw new Error('right.text !== "POINTER_SIZE"')
123-
return factory.createNumericLiteral(`${left.text as string}${defines.MEMORY64 ? '8' : '4'}`)
140+
return parseExpression(`${left.text as string}${defines.MEMORY64 ? '8' : '4'}`, factory)
124141
}
125142
if (param.operatorToken.kind === ts.SyntaxKind.AsteriskToken) {
126143
const left = param.left
@@ -544,9 +561,9 @@ class Transform {
544561
undefined,
545562
[
546563
((ts.isNumericLiteral(argv1) || ts.isStringLiteral(argv1)) && argv1.text === '0')
547-
? this.ctx.factory.createNumericLiteral(argv0.text)
564+
? parseExpression(argv0.text, this.ctx.factory)
548565
: (this.ctx.factory.createBinaryExpression(
549-
this.ctx.factory.createNumericLiteral(argv0.text),
566+
parseExpression(argv0.text, this.ctx.factory),
550567
this.ctx.factory.createToken(ts.SyntaxKind.PlusToken),
551568
byteOffsetParameter(this.ctx.factory, this.defines, argv1)
552569
)),
@@ -591,19 +608,19 @@ class Transform {
591608
undefined,
592609
[
593610
((ts.isNumericLiteral(argv1) || ts.isStringLiteral(argv1)) && argv1.text === '0')
594-
? this.ctx.factory.createNumericLiteral(argv0.text)
611+
? parseExpression(argv0.text, this.ctx.factory)
595612
: (this.ctx.factory.createBinaryExpression(
596-
this.ctx.factory.createNumericLiteral(argv0.text),
613+
parseExpression(argv0.text, this.ctx.factory),
597614
this.ctx.factory.createToken(ts.SyntaxKind.PlusToken),
598615
byteOffsetParameter(this.ctx.factory, this.defines, argv1)
599616
)),
600617
methodName === 'setBigInt64' || methodName === 'setBigUint64'
601618
? (this.ctx.factory.createCallExpression(
602619
this.ctx.factory.createIdentifier('BigInt'),
603620
undefined,
604-
[this.ctx.factory.createNumericLiteral(argv2.text)]
621+
[parseExpression(argv2.text, this.ctx.factory)]
605622
))
606-
: this.ctx.factory.createNumericLiteral(argv2.text),
623+
: parseExpression(argv2.text, this.ctx.factory),
607624
this.ctx.factory.createTrue()
608625
]
609626
)
@@ -625,7 +642,7 @@ class Transform {
625642
this.ctx.factory.createCallExpression(
626643
this.ctx.factory.createIdentifier(this.defines.MEMORY64 ? 'BigInt' : 'Number'),
627644
undefined,
628-
[this.ctx.factory.createNumericLiteral(argv1.text)]
645+
[parseExpression(argv1.text, this.ctx.factory)]
629646
)
630647
]
631648
)
@@ -655,9 +672,9 @@ class Transform {
655672
? (this.ctx.factory.createCallExpression(
656673
this.ctx.factory.createIdentifier('Number'),
657674
undefined,
658-
[this.ctx.factory.createNumericLiteral(argv1.text)]
675+
[parseExpression(argv1.text, this.ctx.factory)]
659676
))
660-
: this.ctx.factory.createNumericLiteral(argv1.text)
677+
: parseExpression(argv1.text, this.ctx.factory)
661678
]
662679
))
663680
}

packages/ts-transform-macro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@emnapi/ts-transform-macro",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "C style define macros for TypeScript",
55
"type": "commonjs",
66
"main": "./lib/index.js",

packages/ts-transform-macro/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class Transform {
9292
const enumValue = checker.getConstantValue(node)
9393
if (typeof enumValue === 'number') {
9494
return ts.addSyntheticTrailingComment(
95-
factory.createNumericLiteral(enumValue),
95+
enumValue < 0
96+
? factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(-enumValue))
97+
: factory.createNumericLiteral(enumValue),
9698
ts.SyntaxKind.MultiLineCommentTrivia,
9799
` ${node.expression.text as string}.${node.name.text as string} `,
98100
false

0 commit comments

Comments
 (0)