Files
codegraph/__tests__/fixtures/kernel-parity/torture.js
T
9181dd1ef3 fix(extraction): land upstream declaration initializer walks (#1511) (#1802)
Squash danusha2345's PR #1511 at d282f9e8 onto main 8c9c4761,
preserving its nine non-merge commits and main's existing Unreleased notes.
Calls in Kotlin, Java, TS/JS, Scala, Rust and Python declaration initializers
now retain the owner established by the upstream regression expectations.
Include the upstream CFML, dynamic-dispatch summary and viewer follow-ups.

Linux fail-to-pass validation (Node 22.19.0, rebuilt dist and native kernel):
- Before: TS load belonged to file:app.ts; Python/Kotlin/Scala/Rust calls
  vanished; Java lost the field-lambda, anonymous override and eager calls.
- After: all six languages PASS; 12 native/WASM LF/CRLF parity checks PASS.
- Focused initializer regressions: 10 passed with CODEGRAPH_KERNEL=0 and
  10 passed with the kernel enabled; Kotlin's grammar fallback is recorded.
- Related regression suites: 879 passed, 1 skipped across 15 test files.
- Evidence: /workspace/cg-1510-repro/before and /workspace/cg-1510-repro/after
  (combined test output: after/vitest.log).

Fixes #1510
Supersedes #1511

Co-authored-by: Colby McHenry <colbymchenry@users.noreply.github.com>
Co-authored-by: danusha2345 <ewidusoc498@gmail.com>
2026-09-08 17:33:45 -05:00

95 lines
2.3 KiB
JavaScript

/**
* JS-grammar torture fixture (javascript variant: no type machinery, JS class
* fields use `field_definition` with a `property` field).
*/
import { EventEmitter } from 'node:events';
const { promisify } = require('node:util');
/** Legacy prototype-style helper. */
function legacyHelper(a, b) {
return a + b;
}
const arrow = (x) => legacyHelper(x, 1);
class Widget extends EventEmitter {
static registry = new Map();
#privateField = 1;
label = 'w';
onTick = () => {
this.render();
};
wrapped = debounce(function () {
expensive();
}, 50);
constructor(opts) {
super();
this.opts = opts;
register(this.onTick);
}
render() {
paint(this.label);
}
static create(opts) {
return new Widget(opts);
}
}
// AMD-style wrapper — anonymous, but inner functions must still surface.
(function () {
function hiddenInner() {
return 7;
}
hiddenInner();
})();
module.exports.makeWidget = function makeWidget(opts) {
return Widget.create(opts);
};
// Vuex module shape (store-file signals: mutations + actions + getters).
const mutations = {
SET_USER(state, user) {
state.user = user;
},
};
const actions = {
async loadUser({ commit }, id) {
const user = await fetchUser(id);
commit('SET_USER', user);
},
};
export default {
namespaced: true,
state: () => ({ user: null }),
mutations,
actions,
getters: {
userName(state) {
return state.user?.name;
},
},
};
// Initializer walks attributed to the declared symbol (#693). A plain call
// leaked to the FILE node; a non-exported object literal was skipped outright.
const eagerConfig = loadConfig();
const handlerMap = { onSave: () => persist(eagerConfig), onLoad: loadConfig() };
const lazyList = [() => persist(eagerConfig)];
// --- CommonJS export assignments (#1675) -----------------------------------
exports.getItems = async (req, res) => { res.json(await findItems()); };
module.exports.deleteItem = function (req, res) { removeItem(req.params.id); res.end(); };
exports.plain = 42;
handlers.onSave = () => { persist(); };
// --- call-expression receivers (#1683) ----------------------------------------
function bucketChains(d, k, v) {
d.setdefault(k, []).append(v);
make().run();
(0, make)().run();
arr[0]().go();
obj.make().run().again();
}