Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rosetta): hoist imports above fixtures #2211

Merged
merged 6 commits into from
Nov 10, 2020

Conversation

RomainMuller
Copy link
Contributor

When import statements are used in a code example, they must be
hoisted at the top of the fixture (if any fixture is used), as they
otherwise may occur at locations where such statements are illegal (they
are only accepted at the top-level scope).

Additionaly, added some (hidden) comments to highlight where the hoisted
imports begin and end, as well as where the snipped code begins and ends
in an attempt to make the "complete source code" a little easier to
navigate, especially in the context of larger fixtures.


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

When `import` statements are used in a code example, they must be
hoisted at the top of the fixture (if any fixture is used), as they
otherwise may occur at locations where such statements are illegal (they
are only accepted at the top-level scope).

Additionaly, added some (hidden) comments to highlight where the hoisted
imports begin and end, as well as where the snipped code begins and ends
in an attempt to make the "complete source code" a little easier to
navigate, especially in the context of larger fixtures.
@RomainMuller RomainMuller requested a review from a team November 2, 2020 11:48
@RomainMuller RomainMuller self-assigned this Nov 2, 2020
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 2, 2020
@@ -66,7 +66,7 @@ export function completeSource(snippet: TypeScriptSnippet) {
function parametersFromSourceDirectives(
source: string,
): [string, Record<string, string>] {
const [firstLine, rest] = source.split('\n', 2);
const [firstLine, ...rest] = source.split('\n');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note - there was a bug right here that my test highlighted (tests with only 1 line of snippet have missed this entirely).

The culprit being that JavaScript's String.split function doesn't work like most folks expect it to when it comes to the limit: instead of limiting the amount of cuts that will be made in the source (like in java) and having the last slice be "the rest", JavaScript cuts on all separators, and the limit restricts the amount of slices returned.

In other words:

// Example.java
final String abc = "a,b,c";
abc.split(",", 2);
//=> ["a", "b,c"]

Versus

// Example.js
const abc = 'a,b,c';
abc.split(',', 2);
//=> ['a', 'b'] // Omitting slice #3, 'c'.

@@ -0,0 +1,17 @@
import { Assembly, SchemaVersion } from '@jsii/spec';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved from jsii/assemblies.test.ts, because rosetta.test.ts imports this function; but the importing actually caused all tests in jsii/assemblies.test.ts to be run twice as a collateral.

@mergify
Copy link
Contributor

mergify bot commented Nov 10, 2020

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Nov 10, 2020
@mergify
Copy link
Contributor

mergify bot commented Nov 10, 2020

Merging (with squash)...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-5lHf64IXfvmr
  • Commit ID: 6c03b7f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 66e2ac8 into main Nov 10, 2020
@mergify mergify bot deleted the rmuller/rosetta-hoist-imports branch November 10, 2020 11:51
@mergify
Copy link
Contributor

mergify bot commented Nov 10, 2020

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants