node-ffi-generate icon indicating copy to clipboard operation
node-ffi-generate copied to clipboard

Generates invalid syntax

Open Qix- opened this issue 3 years ago • 2 comments

When trying to generate FFI bindings for libfuse:

> 50 | types.["fuse_args"] = fuse_args;
     |       ^
  51 | types.["fuse_opt_proc_t"] = fuse_opt_proc_t;
  52 | types.["js_CString"] = js_CString;
  53 | types.["js_int32"] = js_int32;
    at p (/src/qix-/test-fuse-ffi/node_modules/prettier/parser-babel.js:22:1038)
    at d (/src/qix-/test-fuse-ffi/node_modules/prettier/parser-babel.js:22:1271)
    at Object.parse (/src/qix-/test-fuse-ffi/node_modules/prettier/parser-babel.js:27:50335)
    at Object.parse (/src/qix-/test-fuse-ffi/node_modules/prettier/index.js:7361:23)
    at coreFormat (/src/qix-/test-fuse-ffi/node_modules/prettier/index.js:8672:18)
    at formatWithCursor2 (/src/qix-/test-fuse-ffi/node_modules/prettier/index.js:8864:18)
    at /src/qix-/test-fuse-ffi/node_modules/prettier/index.js:39174:12
    at Object.format (/src/qix-/test-fuse-ffi/node_modules/prettier/index.js:39188:12)
    at generate (/src/qix-/test-fuse-ffi/node_modules/@ffi-packager/ffi-generate/lib/generate.js:53:29)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runGenerator (/src/qix-/test-fuse-ffi/node_modules/@ffi-packager/ffi-generate/bin/ffi-generate.js:132:20)
    at async loadAndGenerate (/src/qix-/test-fuse-ffi/node_modules/@ffi-packager/ffi-generate/bin/ffi-generate.js:160:3)
    at async mainAsync (/src/qix-/test-fuse-ffi/node_modules/@ffi-packager/ffi-generate/bin/ffi-generate.js:166:3) {
  loc: { start: { line: 50, column: 7 } },
  codeFrame: '  48 | ;\n' +
    '  49 |\n' +
    '> 50 | types.["fuse_args"] = fuse_args;\n' +
    '     |       ^\n' +
    '  51 | types.["fuse_opt_proc_t"] = fuse_opt_proc_t;\n' +
    '  52 | types.["js_CString"] = js_CString;\n' +
    '  53 | types.["js_int32"] = js_int32;'

Looks like it's incorrectly trying to do 'types.' + name or something, where name == '["fuse_args"]' or something.

cc @joelpurra

Qix- avatar Jun 12 '22 14:06 Qix-

@Qix-: well, that looks broken.

Unsure, but might be fixed in the fork at @node-ffi-packager? If not, feel free to open a pull request there. (I do not personally have time to spend on debugging/fixing.)

  • https://github.com/node-ffi-packager/node-ffi-generate

joelpurra avatar Jun 12 '22 15:06 joelpurra

That's the one I tried, you just don't have issues enabled 😅 So I opened it here.

I tried to look into the source but it's pretty hairy. I've kind of given up on doing this with any amount of certainty :/

Qix- avatar Jun 12 '22 15:06 Qix-