Skip to content

Commit

Permalink
fix(jsii): handle imports from libraries compiled with old jsii (#3245)
Browse files Browse the repository at this point in the history
The fix introduced in #3233 relied on the jsii libraries being recompiled with
symbolid information. This information was introduced in jsii 1.39.0.

With the code from #3233, symbols from libraries compiled with older jsii
versions could not be located and the compilation would fail.

In this PR, restore the compatibility by falling back to the same FQN
that the original code would have guessed. It will not be correct
if the type comes from a submodule, but only CDK is using submodules
and CDK is using a new jsii compiler.



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
rix0rrr authored Dec 10, 2021
1 parent c8d8509 commit 133d1cf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ export class Assembler implements Emitter {
return `unknown.${typeName}`;
}

// If the symbol comes from the current assembly, look up in the tables we are currently building
// If the symbol comes from the current assembly or an assembly whose
// submodules we've already spidered, look up in the tables we are currently building
if (pkg.name === this.projectInfo.name) {
const submodule = this._submoduleMap.get(sym);
if (submodule != null) {
Expand All @@ -537,6 +538,12 @@ export class Assembler implements Emitter {
return `${this.projectInfo.name}.${typeName}`;
}

// This is the fallback: in case we can't find a symbolId for the given
// type, we're return this value. This is for backwards compatibility with
// modules that haven't been compiled to have symbolId support. Those also
// most likely won't be using submodules so this legacy guess will be correct.
const fallbackFqn = `${pkg.name}.${typeName}`;

// Otherwise look up the symbol identifier in the dependency assemblies
const dep = this.projectInfo.dependencyClosure.find(
(d) => d.name === pkg.name,
Expand All @@ -545,7 +552,7 @@ export class Assembler implements Emitter {
this._diagnostics.push(
JsiiDiagnostic.JSII_9000_UNKNOWN_MODULE.createDetached(pkg.name),
);
return `unknown.${typeName}`;
return fallbackFqn;
}
const symbolId = symbolIdentifier(this._typeChecker, sym, {
assembly: dep,
Expand All @@ -569,7 +576,7 @@ export class Assembler implements Emitter {
}
}

return fqn ?? `unknown.${typeName}`;
return fqn ?? fallbackFqn;
}

/**
Expand Down

0 comments on commit 133d1cf

Please sign in to comment.