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

bug: when migrating a ember test, with inline templates; whitespace breaks CommentPlugin #1078

Open
1 task
wondersloth opened this issue May 22, 2023 · 4 comments
Assignees
Labels
bug Something isn't working early-adopters Ultra-Priority flagged from early adopter

Comments

@wondersloth
Copy link
Contributor

wondersloth commented May 22, 2023

Documented issue in TS at microsoft/TypeScript#54366

Affected Version @rehearsal/cli@3.0.5-beta

Bad

    await render(hbs`
        <AssetLoader$DeferredAssetLoader
          @bundle="custom-bundle"
          @fulfilledComponent={{component "artdeco-button" class="test-dummy-component"}}
        />
      `);

Good

    await render(hbs`<AssetLoader$DeferredAssetLoader
          @bundle="custom-bundle"
          @fulfilledComponent={{component "artdeco-button" class="test-dummy-component"}}
        />
      `);

Steps to reproduce

Create a tsconfig.json in packages/addons/asset-loader/tsconfig.json

{
  "extends": "../../../tsconfig.base.json",
  "include": ["addon", "tests", "../../../types/**/*"],
  "references": [],
  "compilerOptions": {
    "allowJs": true,
    "composite": true,
    "declarationDir": "dist-types",
    "paths": {
      "ember-cli-pemberly-tracking/*": [
        "./node_modules/@linkedin/ember-cli-pemberly-tracking/*"
      ],
      "ember-cli-pemberly-tracking/test-support/*": [
        "./node_modules/@linkedin/ember-cli-pemberly-tracking/test-support/*"
      ]
    }
  }
}
$ yarn add -D @rehearsal/cli@3.0.5-beta
$ yarn rehearsal move packages/addons/asset-loader/tests
$ yarn rehearsal fix packages/addons/asset-loader/tests/
// Make a change? Or not.
$ yarn rehearsal fix packages/addons/asset-loader/tests/

Second pass of fix breaks source code, due to plugins not acocunting for offset changes when working through fixes.

First pass

      assert.ok(
        // @ts-expect-error @rehearsal TODO TS2339: Property 'loadBundleStub' does not exist on type 'TestContext'.
        this.loadBundleStub.calledWithExactly('custom-bundle'),
        'asset-loader service was called with correct bundle name'
      );

Imports get updated with

// @ts-expect-error @rehearsal TODO TS6133: The declaration 'Property' is never read or used. Remove the declaration or use it.
import { Property } from 'node_modules/@babel/types/lib';
import { not } from 'node_modules/@types/micromatch';
import { type } from 'os';
import { type } from 'os';

Around line 60 a comment is mangled.

      // @ts-expect-ert'.
      // @ts-expect-error @rehearsal TODO TS2339: Property 'defer' does not exist on type 'TestContext'.
      this.defer.re TODO Property 'loadBundleStub' does not exist on type 'TestContext'.
        // @ts-expect-error @rehearsal TODO TS2339: Property 'this' does not exist on type '"TestContext"'.
        this.loadBundleStub.calledWithExactly('custom-bundle'),
        'asset-loader service was called with correct bundle name'
      );

Rehearsal CLI reports things completed.

➜  voyager-web git:(medwards/asset-loader) ✗ yarn rehearsal fix packages/addons/asset-loader/tests
info:    @rehearsal/fix 3.0.5-beta
✔ Initialize
✔ Analyzing project dependency graph ...
✔ Types Inferred
  30 errors caught by rehearsal
  9 have been fixed by rehearsal
  21 errors need to be fixed manually
  -- 20 ts errors, marked by @ts-expect-error @rehearsal TODO
  -- 1 eslint errors, with details in the report

Additional Recommendations

  • rehearsal should not write to a file that can't be parsed, or prettified.
@wondersloth wondersloth added the bug Something isn't working label May 22, 2023
@wondersloth wondersloth changed the title bug: when migrating a test, and running fix twice, source is broken after plugin applied bug: when migrating a ember test, with inline templates; whitespace breaks CommentPlugin May 22, 2023
@lynchbomb lynchbomb added the early-adopters Ultra-Priority flagged from early adopter label May 23, 2023
@lynchbomb lynchbomb added this to the 4. Self Service milestone May 23, 2023
@lynchbomb
Copy link
Contributor

This is lower priority as its non app code. App code first. Test code second.

@wondersloth
Copy link
Contributor Author

Pausing due to prioritization.

Leaving notes for future investigation:

The ReRehearsePlugin

Fails to remove a comment when a multiline hbs tagged template expression is present.

.getSpanOfEnclosingComment(sourceFile.fileName, tagStart, false);

getSpanOfEnclosingComment returns an incorrect start commentSpan.start

The position does not start at the // but rather 40 to 50 characters earlier in the file.

When the comment is stripped it truncates an incorrect region.

text = text.substring(0, boundary.start) + text.substring(boundary.end);

@egorio
Copy link
Contributor

egorio commented May 23, 2023

One more thing.

Multiple imports, like:

import { type } from 'os';
import { type } from 'os';

should be resolved with EXPERIMENTAL_MODES === drain

@wondersloth
Copy link
Contributor Author

This has been fixed in TS expected release in 5.2.0
microsoft/TypeScript#54366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working early-adopters Ultra-Priority flagged from early adopter
Projects
None yet
Development

No branches or pull requests

4 participants