Expression evaluation needs to handle files with same file names from different libraries
- Dominant language
- Dart
- Stars
- 224
- Forks
- 94
- Avg merge
- 7h 14m
- Merged PRs (30d)
- 2
Description
In the case below, when we have files with same name in different directories in the same package, expression evaluator fails to retrieve correct library variable (used in require statement to reload the library)
Context: variables containing library code are usually optimized away in v8 and we bring them back using require statement of the form:
`library = require('module').libraryField;`
**Example:**
For the following JS file:
```
dart.trackLibraries("web/main", {
"org-dartlang-app:///web/sub/main.dart": main,
"org-dartlang-app:///web/main.dart": main$
}...
// Exports:
return {
web__sub__main: main,
web__main: main$
};
```
We need to create
```
let main = require('web/main').web__sub__main;
let main$ = require('web/main').web__main;
```
in other words, for current module:
```
for (var library in module.libraries) {
var name = pathToJSIdentifier(library);
var field = TempId(pathToJSIdentifier(library));
// let $name = require('$module').$field
}
```
and for other modules:
```
for (var library in module.libraries) {
var name = pathToJSIdentifier(library);
var field = name;
// let $name = require('$module').$field
}
```
Note that variable names are not available during during JS evaluation, but we might be able to retrieve them from JS AST's during compilation.
**See original conversation:**
I am a bit confused by this part - does it support more than modules immediately under web (`web/main.dart.js`)? For instance how would this distinguish that from `web/sub/main.dart.js`?
_Originally posted by @jakemac53 in https://github.com/dart-lang/webdev/pull/879#discussion_r374742367
Contributor guide
Research direction
Start at the expression evaluator's handling of module.libraries, pathToJSIdentifier, and TempId, then compare the generated require statements in the example. Done means libraries with the same file name in different directories resolve to distinct exported fields for both the current and other modules, with relevant evaluator or compilation tests added.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, javascript
- Domain
- tooling, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100