-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rosetta): incorrect transliteration for selective imports (#3508)
Go does nto support "selective" imports, and has limited symbol aliasing support. Instead of attempting to transliterate selective imports with a one-to-one semantic mapping, resolve the imported symbols and emit the correct qualified original name instead. This results in more idiomatic (and likely more correct) go code. For example: ```ts import { Foo as RenamedFoo, Bar } from 'baz'; const foo = new RenamedFoo(); Bar.baz(foo); ``` Should transliterate to something looking like: ```go import "github.com/aws-samples/dummy/baz" foo := baz.NewFoo() Bar_baz(foo) ``` --- Bonus content: - Now emits README.md for submodules, too (was previously ignored). - Missing newlines between go import statements are now inserted. --- 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
1 parent
3648117
commit 8eec086
Showing
11 changed files
with
144 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,16 @@ | ||
import { join } from 'path'; | ||
|
||
import { EmitContext } from './emit-context'; | ||
// import { Translation } from 'jsii-rosetta'; | ||
// import { INCOMPLETE_DISCLAIMER_COMPILING, INCOMPLETE_DISCLAIMER_NONCOMPILING } from '..'; | ||
|
||
export class ReadmeFile { | ||
public constructor( | ||
private readonly packageName: string, | ||
private readonly document: string, | ||
private readonly directory: string, | ||
) {} | ||
|
||
public emit({ code /*, rosetta */ }: EmitContext) { | ||
const nameParts = this.packageName.split('.'); | ||
const file = join( | ||
...nameParts.slice(0, nameParts.length - 11), | ||
'README.md', | ||
); | ||
|
||
code.openFile(file); | ||
const translated = this.document; // rosetta.translateSnippetsInMarkdown(this.document, 'go', prependDisclaimer); | ||
for (const line of translated.split('\n')) { | ||
code.line(line); | ||
} | ||
code.closeFile(file); | ||
} | ||
|
||
/* | ||
function prependDisclaimer(translation: Translation) { | ||
const source = addDisclaimerIfNeeded(); | ||
return { language: translation.language, source }; | ||
function addDisclaimerIfNeeded(): string { | ||
if (translation.didCompile && INCOMPLETE_DISCLAIMER_COMPILING) { | ||
return `// ${INCOMPLETE_DISCLAIMER_COMPILING}\n\n${translation.source}`; | ||
} | ||
if (!translation.didCompile && INCOMPLETE_DISCLAIMER_NONCOMPILING) { | ||
return `// ${INCOMPLETE_DISCLAIMER_NONCOMPILING}\n\n${translation.source}`; | ||
} | ||
return translation.source; | ||
public emit({ documenter }: EmitContext) { | ||
if (!this.document) { | ||
return; | ||
} | ||
documenter.emitReadme(this.packageName, this.document, this.directory); | ||
} | ||
*/ | ||
} |
42 changes: 32 additions & 10 deletions
42
packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.