Skip to content

Commit

Permalink
Fix presubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
fallaciousreasoning committed Feb 18, 2025
1 parent 6121b17 commit 5ab3877
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = {
],
'object-shorthand': 0,
'n/no-callback-literal': 0,
'no-template-curly-in-string': 0,
'@typescript-eslint/await-thenable': 0,
'@typescript-eslint/consistent-generic-constructors': 0,
'@typescript-eslint/ban-ts-comment': 0,
Expand Down
14 changes: 6 additions & 8 deletions build/commands/scripts/lit_mangler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ describe('Attribute handling', () => {
expect(div?.getAttribute('?hidden')).toBe('${this.foo || this.bar || "<p>haha</p>"}')
}, template)
})

});

describe('End to end', () => {
Expand All @@ -94,7 +93,7 @@ export function getList(this: string[]) {
Hi All!
Greetings could be: \${["Hi", 'Kiora', 'Gidday'].map(g => html\`<b>\${g}</b>\`).join('\n')}
<div class="greetings count-\${this.length}">
\${this.map(t => getHtml.call({ name: t, data: {} }))}
</div>
Expand All @@ -120,7 +119,7 @@ export function getList(this: string[]) {
Hi All!
Greetings could be: \${["Hi", 'Kiora', 'Gidday'].map(g => html\`<b>\${g}</b>\`).join('\n')}
<div class="greetings count-\${this.length}">
\${this.map(t => getHtml.call({ name: t, data: {} }))}
</div>
Expand Down Expand Up @@ -159,7 +158,7 @@ export function getList(this: string[]) {
Hi All!
Greetings could be: \${["Hi", 'Kiora', 'Gidday'].map(g => html\`$$lit_mangler_3$$\`).join('\n')}
<div class="greetings count-\${this.length}">
\${this.map(t => getHtml.call({ name: t, data: {} }))}
</div>
Expand Down Expand Up @@ -218,14 +217,14 @@ export function getList(this: string[]) {
utilsForTest.mangle(e => {
const root = e.querySelector('div')
root?.removeAttribute('?hidden')
root!.childNodes[0].textContent = root!.childNodes[0].textContent!.replace("Hi All!", '')
root!.childNodes[0].textContent = root!.childNodes[0].textContent!.replace(" Hi All!\n", '')
root?.prepend(`<div>Greetings from the Mangler</div>`)
}, t => t.text.includes('Hi All!'))

utilsForTest.mangle(e => {
e.querySelector('b')?.setAttribute('hidden', '${g === "hi"}')
}, t => t.text.startsWith('<b'))

utilsForTest.mangle(e => {
const root = e.querySelector('div')
root?.setAttribute('class', '${this.name === "jay" && "best"}')
Expand All @@ -245,10 +244,9 @@ export function getHtml(this: FakeElement & { name: string }) {
export function getList(this: string[]) {
const haxor = 'whatevs" onload="javascript:alert(\`pwnd\`)'
return html\`<div .count="\${this.length}" @click="\${console.log}" data-haxor="\${haxor}"><div>Greetings from the Mangler</div>
Greetings could be: \${["Hi", 'Kiora', 'Gidday'].map(g => html\`<b hidden="\${g === "hi"}">\${g}</b>\`).join('\n')}
<div class="greetings count-\${this.length}">
\${this.map(t => getHtml.call({ name: t, data: {} }))}
</div>
Expand Down
4 changes: 2 additions & 2 deletions build/commands/scripts/lit_mangler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ const write = (file: string) => {

/**
* Mangles a given html template using the given mangler function.
*
*
* Example usage:
* mangle((element) => element.textContent = "foo", t => t.text.includes('allow-incognito'))
*
*
* @param mangler The function to use to mangle the template.
* @param getTemplate The template to mangle, or a predicate to find a matching template. If undefined, the first html template will be used.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ mangle((element) => {
section.textContent = '$i18n{privateInfoWarning}'
section.append('<span ?hidden=${!this.data.incognitoAccess.isActive}> $i18n{spanningInfoWarning}</span>')
section.append('<span> $i18n{privateAndTorInfoWarning}</span>')
}, t => t.text.includes('id="allow-incognito"'))
}, t => t.text.includes('id="allow-incognito"'))
3 changes: 2 additions & 1 deletion chromium_src/tools/grit/preprocess_if_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def run_mangler(mangler_file, preprocess_file):
'npx', '--no', '--', 'tsx', '--tsconfig', ts_config, lit_mangler,
'mangle', '-m', mangler_file, '-i', preprocess_file, '-o',
preprocess_file
])
],
check=True)


def get_chromium_src_files(in_folder, in_files):
Expand Down
7 changes: 6 additions & 1 deletion tools/chromium_src/check_chromium_src.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,12 @@ def do_check_overrides(self):
display_override_filepath = os.path.join('chromium_src',
override_filepath)
if not os.path.isfile(original_filepath):
if self.gen_buildir is None:
if override_filepath.endswith(
'.mangle.html.ts') and os.path.isfile(
original_filepath.replace('.mangle.html.ts',
'.html.ts')):
original_filepath_found = True
elif self.gen_buildir is None:
# When invoked from presubmit there's no gen_dir, so we can
# try to at least check that the include in the override is
# consistent with overriding a generated file.
Expand Down

0 comments on commit 5ab3877

Please sign in to comment.