Code Monkey home page Code Monkey logo

bug-ng16-input-transform's Introduction

Angular 16 Bug Repro Case - for @Input({transform: ..})

This is a repro case for: angular/angular#51424

Created on 8/18/2023 with:

yarn dlx --package @angular/cli ng new ng16-standalone-lib --standalone --package-manager=yarn --create-application=false --minimal --commit=false

# Check for upgrade latest
yarn ng update @angular/core @angular/cli @angular/common
yarn upgrade-interactive

# Add libraries
yarn ng g library ui-components -p ui --project-root libs/ui-components --standalone
yarn ng g library util -p util --project-root libs/util --standalone

Bugbug

Issue Title: Directive compile broken when using @Input transform

The bug can be reproduced by:

git clone https://github.com/johncrim/bug-ng16-input-transform
yarn
yarn build:all

The compile error is:

------------------------------------------------------------------------------
Building entry point 'ui-components/sticky'
------------------------------------------------------------------------------
✖ Compiling with Angular sources in Ivy partial compilation mode.
libs/ui-components/sticky/src/Sticky.component.ts:10:5 - error NG2012: Component imports must be standalone components, directives, pipes, or must be NgModules.

10     MirrorWidthDirective
       ~~~~~~~~~~~~~~~~~~~~

error Command failed with exit code 1.

This error is caused by the use of @Input({transform: ...}) in MirrorWidthDirective. The problem is that the use of the input transform feature breaks the build output: The contents of dist\ui-components\fesm2022\ui-components-mirror-size.mjs show that class MirrorWidthDirective is missing the static ɵdir and ɵfac properties:

let MirrorWidthDirective = class MirrorWidthDirective {
  // ... (class properties and methods)
};
__decorate([
    Input({ alias: 'ui-mirror-width', required: true, transform: coerceElement })
], MirrorWidthDirective.prototype, "source", void 0);
MirrorWidthDirective = __decorate([
    Directive({
        selector: '[ui-mirror-width]',
        standalone: true,
        exportAs: 'ui-mirror-width'
    })
], MirrorWidthDirective);

The similar directive MirrorHeightDirective is equivalent but omits use of the @Input transform. It is in the same project, but the compiler output (in dist\ui-components\fesm2022\ui-components-mirror-size.mjs) is:

class MirrorHeightDirective {
  // ... (class properties and methods)
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: MirrorHeightDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.1", type: MirrorHeightDirective, isStandalone: true, selector: "[ui-mirror-height]", inputs: { source: ["ui-mirror-height", "source"] }, exportAs: ["ui-mirror-height"], usesOnChanges: true, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: MirrorHeightDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[ui-mirror-height]',
                    standalone: true,
                    exportAs: 'ui-mirror-height'
                }]
        }], propDecorators: { source: [{
                type: Input,
                args: [{ alias: 'ui-mirror-height', required: true }]
            }] } });

The second directive can be imported, but the first one can't, b/c the second is recognized as a directive b/c static ɵdir exists.

bug-ng16-input-transform's People

Contributors

johncrim avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.