angular / angular/angular-cli

Angular schematics generates blank lines through template

未关闭
#27,896 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area: @angular-devkit/schematics freq1: low severity2: inconvenient type: bug/fix workaround2: non-obvious
主要语言
TypeScript
星标
27k
派生
11.8k
平均合并
14 小时 23 分钟
30 天内合并 PR
162

描述

### Command

generate

### 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

I have ng schematics template `__name@dasherize__.component.html` with content :

> <% for (let row of getComponents().rows) { %>
>


> <% for (let field of row.fields) { %>
> <% if (field.type === 'InputStrxing') { %>
>
>
>
> <% } %>
> <% } %>
>

> <% } %>

I build it with :

npm run build
schematics .:ui-generator --name=hello

Generated code creates empty lines on place where is put command "<%" in template, see:

>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

Is there anyway these white spaces can be avoided. If we have to do it manually, it might kill the purpose of this code generator tool

### Minimal Reproduction

Write a schematic template code with inline code <% inline code %>. Then build and generate code using commands

npm run build
schematics .:ui-generator --name=hello

We can see generated code is having while spaces wherever inline code is present.

### Exception or Error

_No response_

### Your Environment

```text
ng analytics disable --global

Global setting: enabled
Local setting: No local workspace configuration file.
Effective status: enabled

_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/

Angular CLI: 16.2.14
Node: 18.19.1
Package Manager: npm 10.2.4
OS: darwin arm64

Angular: undefined
...

Package Version
------------------------------------------------------
@angular-devkit/architect 0.1602.14
@angular-devkit/core 16.2.14
@angular-devkit/schematics 16.2.14
@schematics/angular 16.2.14
typescript 5.1.6
```

### Anything else relevant?

_No response_

贡献指南

打开贡献指南

调研方向

使用 npm run build 和 schematics .:ui-generator --name=hello 重现内联 <% ... %> schematic 模板中的空行。首先追踪 Angular CLI schematics 如何渲染模板命令,然后验证生成的输出会省略仅属于命令的空白,同时保留周围的内容。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
cli, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。