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: [ngtools] Replace resource transformer issue with conditional templateUrl #27611

Open
1 task
ahnpnl opened this issue May 8, 2024 · 4 comments
Open
1 task

Comments

@ahnpnl
Copy link

ahnpnl commented May 8, 2024

Command

test

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When having conditional templateUrl like this

  templateUrl:
    true === true
        ? './dashboard.component.html'
        : './dashboard.component.copy.html',

replace_resources.ts couldn't transform into proper codes (either require or import)

Minimal Reproduction

// esm

//...
AppComponent = __decorate([
    Component({
        selector: 'app-root',
        templateUrl: true === true
            ? './app.component.html'
            : './app.component.copy.html',
        styles: [__NG_CLI_RESOURCE__0, __NG_CLI_RESOURCE__1]
    })
], AppComponent);
// commonjs

//...
exports.AppComponent = AppComponent = tslib_1.__decorate([
    (0, core_1.Component)({
        selector: 'app-root',
        templateUrl: true === true
            ? './app.component.html'
            : './app.component.copy.html',
        styles: [require("./app.component.css?ngResource"), require("./app.component.2.css?ngResource")]
    })
], AppComponent);

Exception or Error

Component 'AppComponent' is not resolved:
     - templateUrl: ./app.component.html
    Did you run and wait for 'resolveComponentResources()'?


### Your Environment

```text
Angular CLI: 17.3.6
Node: 20.12.2
Package Manager: yarn 1.22.17
OS: darwin x64

Angular: 18.0.0-rc.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.0.0-EXPERIMENTAL-PLACEHOLDER
@angular-devkit/core         0.0.0-PLACEHOLDER
@angular-devkit/schematics   0.0.0-PLACEHOLDER
@angular/bazel               18.1.0-next.0+sha-1872fcd
@angular/build-tooling       0.0.0-e6e98d32d7d4d350ecf4ec10ad9c7e75198daabd
@angular/ng-dev              <error>
@schematics/angular          0.0.0-PLACEHOLDER
ng-packagr                   18.0.0-rc.0
rxjs                         7.8.1
typescript                   5.4.5
webpack                      5.91.0
zone.js                      0.14.4

Anything else relevant?

Related to this bug thymikee/jest-preset-angular#1866

@ahnpnl ahnpnl changed the title [ngtools] Replace resource transformer issue with conditional templateUrl [Bug] [ngtools] Replace resource transformer issue with conditional templateUrl May 8, 2024
@ahnpnl ahnpnl changed the title [Bug] [ngtools] Replace resource transformer issue with conditional templateUrl Bug: [ngtools] Replace resource transformer issue with conditional templateUrl May 8, 2024
@alan-agius4
Copy link
Collaborator

alan-agius4 commented May 8, 2024

During JIT compilations, this is expected to fail since the transformer doesn't evaluate expressions. The templateUrl should be a string literal.

@ahnpnl
Copy link
Author

ahnpnl commented May 8, 2024

Should we throw an error from transformer to have a more descriptive error for this case? The current error message isn’t really clear about this caveat

@alan-agius4
Copy link
Collaborator

We should probably add an error or warning message.

@santoshyadavdev
Copy link
Contributor

@alan-agius4 I can take this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants