Skip to content

Commit e369c03

Browse files
authored
generate html should keep id when script-export is set (#6276)
1 parent ec218d3 commit e369c03

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

packages/core/src/code_manager/model/HtmlGenerator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default class HTMLGenerator extends Model {
3434
id &&
3535
id[0] === 'i' && // all autogenerated IDs start with 'i'
3636
!mod.get('script') && // if the component has script, we have to leave the ID
37+
!mod.get('script-export') && // if the component has script, we have to leave the ID
3738
!mod.get('attributes')!.id && // id is not intentionally in attributes
3839
idRules.indexOf(id) < 0 // we shouldn't have any rule with this ID
3940
) {

packages/core/test/specs/code_manager/model/CodeModels.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,37 @@ describe('HtmlGenerator', () => {
6262
});
6363
expect(obj.build(m1)).toEqual('<article data-test1="value1" data-test2="value2" class="class1 class2"></article>');
6464
});
65+
66+
test('Build correctly component with id preserved when script is defined', () => {
67+
const m1 = comp.get('components').add({
68+
tagName: 'article',
69+
});
70+
m1.set('script', 'anything');
71+
expect(obj.build(m1, { cleanId: true, em })).toEqual(`<article id="${m1.getId()}"></article>`);
72+
});
73+
74+
test('Build correctly component with id preserved when script-export is defined', () => {
75+
const m1 = comp.get('components').add({
76+
tagName: 'article',
77+
});
78+
m1.set('script-export', 'anything');
79+
expect(obj.build(m1, { cleanId: true, em })).toEqual(`<article id="${m1.getId()}"></article>`);
80+
});
81+
82+
test('Build correctly component with id preserved when id is explicitly set ', () => {
83+
const m1 = comp.get('components').add({
84+
tagName: 'article',
85+
});
86+
m1.setId('i11');
87+
expect(obj.build(m1, { cleanId: true, em })).toEqual(`<article id="i11"></article>`);
88+
});
89+
90+
test('Build correctly component with cleanId is enabled and id is not required ', () => {
91+
const m1 = comp.get('components').add({
92+
tagName: 'article',
93+
});
94+
expect(obj.build(m1, { cleanId: true, em })).toEqual(`<article></article>`);
95+
});
6596
});
6697

6798
describe('CssGenerator', () => {

0 commit comments

Comments
 (0)