source-academy / js-slang

Implementations of sublanguages of JavaScript, TypeScript, Scheme and Python
https://source-academy.github.io/source/
Apache License 2.0
70 stars 104 forks source link

Fix incorrect `function.name` for aliased imports #1484

Open RichDom2185 opened 1 year ago

RichDom2185 commented 1 year ago

Uses Object.defineProperty to set the correct function.name value for aliased imports in:

Did not do so for interpreter/interpreter.ts due to the deprecation note in #1476.

How to test

Consider the following program:

import { play as asdf } from 'sound';

asdf("test");

Previously, this will result in the following error:

Error: play is expecting sound, but encountered test

Now, it will result in:

Error: asdf is expecting sound, but encountered test

Tested with:

coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 7593472306


Totals Coverage Status
Change from base Build 7593229382: -0.001%
Covered Lines: 10896
Relevant Lines: 12709

💛 - Coveralls
leeyi45 commented 10 months ago

If multiple files alias the same import the name information is lost

// a.js
import { show as s } from 'rune';
export function a(x) {
  return s(x);
}

// b.js
import { show as b } from 'rune';
import { a } from './a.js';

b(0);
a(0);

would theoretically cause the second call to a to display the function's name as 'b' (or vice versa). However, right now we only use the Function.name syntax when throwing errors, so this isn't an issue at the present moment