Skip to content

Commit

Permalink
update dependencies (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi authored Jul 21, 2024
1 parent 414439f commit b4b4d40
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 33 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@
},
"license": "MIT",
"devDependencies": {
"@microsoft/api-extractor": "^7.39.0",
"@microsoft/api-extractor": "^7.47.0",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@rollup/plugin-typescript": "^11.1.6",
"@tybys/cross-zip": "^3.1.0",
"@tybys/ts-transform-pure-class": "^0.1.1",
"@tybys/tsapi": "^0.6.0",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.10.6",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"eslint": "^8.56.0",
"eslint-config-standard-with-typescript": "^43.0.0",
"@types/node": "^20.14.10",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.57.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.4.0",
"fs-extra": "^11.2.0",
"glob": "^10.3.10",
"rollup": "^4.9.1",
"typescript": "~5.3.3"
"glob": "^10.4.5",
"rollup": "^4.18.1",
"typescript": "~5.4.2"
},
"workspaces": [
"packages/ts-transform-macro",
Expand Down
14 changes: 7 additions & 7 deletions packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"description": "emnapi test",
"main": "index.js",
"devDependencies": {
"@tybys/wasm-util": "^0.8.0",
"chalk": "^4.1.1",
"cmake-js": "^7.1.1",
"@tybys/wasm-util": "^0.8.3",
"chalk": "^4.1.2",
"cmake-js": "^7.3.0",
"cross-env": "^7.0.3",
"glob": "^7.2.0",
"memfs-browser": "^3.4.13000",
"node-addon-api": "7.0.0",
"why-is-node-running": "^2.2.2"
"glob": "^7.2.3",
"memfs-browser": "^3.5.10302",
"node-addon-api": "8.1.0",
"why-is-node-running": "^2.3.0"
},
"scripts": {
"rebuild": "cross-env UV_THREADPOOL_SIZE=2 node ./script/build-emscripten.js Debug",
Expand Down
39 changes: 28 additions & 11 deletions packages/ts-transform-emscripten-parse-tools/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
VisitResult,
Statement
} from 'typescript'
import { cloneNode, type CloneNodeOptions } from 'ts-clone-node'

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

function parseExpression (input: string, factory?: NodeFactory): Expression {
const expression: Expression = (ts.createSourceFile('', input, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS).statements[0] as ExpressionStatement).expression
const cloneOptions: Partial<CloneNodeOptions<Expression>> = {
typescript: ts,
factory,
setOriginalNodes: true,
setParents: true,
preserveComments: true,
preserveSymbols: true
}
return cloneNode(expression, cloneOptions)
}

function byteOffsetParameter (factory: NodeFactory, defines: Record<string, any>, param: Expression): NumericLiteral | Expression {
if (ts.isNumericLiteral(param) || ts.isStringLiteral(param)) {
if (ts.isNumericLiteral(param)) {
return factory.createNumericLiteral(param.text)
}
if (ts.isStringLiteral(param)) {
return parseExpression(param.text, factory)
}
if (ts.isIdentifier(param)) {
if (param.text === 'POINTER_SIZE') {
return factory.createNumericLiteral(defines.MEMORY64 ? 8 : 4)
Expand All @@ -120,7 +137,7 @@ function byteOffsetParameter (factory: NodeFactory, defines: Record<string, any>
if (!ts.isStringLiteral(left)) throw new Error('left must be string literal')
if (!ts.isIdentifier(right)) throw new Error('right must be identifier')
if (right.text !== 'POINTER_SIZE') throw new Error('right.text !== "POINTER_SIZE"')
return factory.createNumericLiteral(`${left.text as string}${defines.MEMORY64 ? '8' : '4'}`)
return parseExpression(`${left.text as string}${defines.MEMORY64 ? '8' : '4'}`, factory)
}
if (param.operatorToken.kind === ts.SyntaxKind.AsteriskToken) {
const left = param.left
Expand Down Expand Up @@ -544,9 +561,9 @@ class Transform {
undefined,
[
((ts.isNumericLiteral(argv1) || ts.isStringLiteral(argv1)) && argv1.text === '0')
? this.ctx.factory.createNumericLiteral(argv0.text)
? parseExpression(argv0.text, this.ctx.factory)
: (this.ctx.factory.createBinaryExpression(
this.ctx.factory.createNumericLiteral(argv0.text),
parseExpression(argv0.text, this.ctx.factory),
this.ctx.factory.createToken(ts.SyntaxKind.PlusToken),
byteOffsetParameter(this.ctx.factory, this.defines, argv1)
)),
Expand Down Expand Up @@ -591,19 +608,19 @@ class Transform {
undefined,
[
((ts.isNumericLiteral(argv1) || ts.isStringLiteral(argv1)) && argv1.text === '0')
? this.ctx.factory.createNumericLiteral(argv0.text)
? parseExpression(argv0.text, this.ctx.factory)
: (this.ctx.factory.createBinaryExpression(
this.ctx.factory.createNumericLiteral(argv0.text),
parseExpression(argv0.text, this.ctx.factory),
this.ctx.factory.createToken(ts.SyntaxKind.PlusToken),
byteOffsetParameter(this.ctx.factory, this.defines, argv1)
)),
methodName === 'setBigInt64' || methodName === 'setBigUint64'
? (this.ctx.factory.createCallExpression(
this.ctx.factory.createIdentifier('BigInt'),
undefined,
[this.ctx.factory.createNumericLiteral(argv2.text)]
[parseExpression(argv2.text, this.ctx.factory)]
))
: this.ctx.factory.createNumericLiteral(argv2.text),
: parseExpression(argv2.text, this.ctx.factory),
this.ctx.factory.createTrue()
]
)
Expand All @@ -625,7 +642,7 @@ class Transform {
this.ctx.factory.createCallExpression(
this.ctx.factory.createIdentifier(this.defines.MEMORY64 ? 'BigInt' : 'Number'),
undefined,
[this.ctx.factory.createNumericLiteral(argv1.text)]
[parseExpression(argv1.text, this.ctx.factory)]
)
]
)
Expand Down Expand Up @@ -655,9 +672,9 @@ class Transform {
? (this.ctx.factory.createCallExpression(
this.ctx.factory.createIdentifier('Number'),
undefined,
[this.ctx.factory.createNumericLiteral(argv1.text)]
[parseExpression(argv1.text, this.ctx.factory)]
))
: this.ctx.factory.createNumericLiteral(argv1.text)
: parseExpression(argv1.text, this.ctx.factory)
]
))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-transform-macro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emnapi/ts-transform-macro",
"version": "1.0.0",
"version": "1.0.1",
"description": "C style define macros for TypeScript",
"type": "commonjs",
"main": "./lib/index.js",
Expand Down
4 changes: 3 additions & 1 deletion packages/ts-transform-macro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class Transform {
const enumValue = checker.getConstantValue(node)
if (typeof enumValue === 'number') {
return ts.addSyntheticTrailingComment(
factory.createNumericLiteral(enumValue),
enumValue < 0
? factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(-enumValue))
: factory.createNumericLiteral(enumValue),
ts.SyntaxKind.MultiLineCommentTrivia,
` ${node.expression.text as string}.${node.name.text as string} `,
false
Expand Down

0 comments on commit b4b4d40

Please sign in to comment.