JavaScript: Fix exported name of default re-exports.

A default re-export (not part of the standard yet) looks like this:

```
export f from 'mod';
```

What this means is that the default export of `mod` is re-exported under the name `f`.

Default re-export specifiers (like `f` in this example) are modelled as a kind of default export specifier in our library, but unlike normal default export specifiers they do not export the name `default`.

This was previously not modelled correctly, leading to surprising errors down the line, for example in type inference where we suddenly would no longer be able to resolve an import that otherwise looked resolvable.
This commit is contained in:
Max Schaefer
2018-08-17 12:14:41 +01:00
parent 44e4b25f42
commit a9f1e21363
19 changed files with 79 additions and 8 deletions

View File

@@ -428,22 +428,39 @@ class ExportSpecifier extends Expr, @exportspecifier {
string getExportedName() { result = getExported().getName() }
}
/** A named export specifier. */
/**
* A named export specifier, for example `v` in `export { v }`.
*/
class NamedExportSpecifier extends ExportSpecifier, @namedexportspecifier {
}
/** A default export specifier. */
/**
* A default export specifier, for example `default` in `export default 42`,
* or `v` in `export v from "mod"`.
*/
class ExportDefaultSpecifier extends ExportSpecifier, @exportdefaultspecifier {
override string getLocalName() {
getExportDeclaration() instanceof ReExportDeclaration and result = "default"
}
override string getExportedName() {
result = "default"
}
}
/** A namespace export specifier. */
/**
* A default export specifier in a re-export declaration, for example `v` in
* `export v from "mod"`.
*/
class ReExportDefaultSpecifier extends ExportDefaultSpecifier {
ReExportDefaultSpecifier() {
getExportDeclaration() instanceof ReExportDeclaration
}
override string getLocalName() { result = "default" }
override string getExportedName() { result = getExported().getName() }
}
/**
* A namespace export specifier, for example `*` in `export * from "mod"`.
*/
class ExportNamespaceSpecifier extends ExportSpecifier, @exportnamespacespecifier {
}