From 61e7e130d089a6dbecc5318e00299d2a602bee60 Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Thu, 11 Nov 2021 10:49:54 -0800 Subject: [PATCH 1/5] Handle static components from getters Allow components from {{#this.foobar}}baz{{/this.foobar}} to be static. --- packages/compat/src/resolver-transform.ts | 9 +++++++++ packages/compat/tests/resolver.test.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/compat/src/resolver-transform.ts b/packages/compat/src/resolver-transform.ts index 9b1cdceea..3cc39c79d 100644 --- a/packages/compat/src/resolver-transform.ts +++ b/packages/compat/src/resolver-transform.ts @@ -28,6 +28,9 @@ export function makeResolverTransform(resolver: Resolver) { if (scopeStack.inScope(node.path.parts[0])) { return; } + if (node.path.head.type === 'ThisHead') { + return; + } if (node.path.parts.length > 1) { // paths with a dot in them (which therefore split into more than // one "part") are classically understood by ember to be contextual @@ -61,6 +64,9 @@ export function makeResolverTransform(resolver: Resolver) { if (node.path.type !== 'PathExpression') { return; } + if (node.path.original.includes('liquidif')) { + debugger; + } if (node.path.this === true) { return; } @@ -77,6 +83,9 @@ export function makeResolverTransform(resolver: Resolver) { if (node.path.type !== 'PathExpression') { return; } + if (node.path.original.includes('liquidif')) { + debugger; + } if (scopeStack.inScope(node.path.parts[0])) { return; } diff --git a/packages/compat/tests/resolver.test.ts b/packages/compat/tests/resolver.test.ts index 0b054126f..2032bed6e 100644 --- a/packages/compat/tests/resolver.test.ts +++ b/packages/compat/tests/resolver.test.ts @@ -476,6 +476,20 @@ describe('compat-resolver', function () { let findDependencies = configure({ staticHelpers: true }); expect(findDependencies('templates/application.hbs', `{{(this.myHelper 42)}}`)).toEqual([]); }); + test('class defined component not failing if there is no arguments', function () { + let findDependencies = configure({ staticComponents: true, staticHelpers: true }); + expect(findDependencies('templates/application.hbs', `{{this.myComponent}}`)).toEqual([]); + }); + test('class defined component not failing if there is a block', function () { + let findDependencies = configure({ staticComponents: true, staticHelpers: true }); + expect(findDependencies('templates/application.hbs', `{{#this.myComponent}}hello{{/this.myComponent}}`)).toEqual( + [] + ); + }); + test('class defined component not failing with arguments', function () { + let findDependencies = configure({ staticComponents: true, staticHelpers: true }); + expect(findDependencies('templates/application.hbs', `{{#this.myComponent 42}}{{/this.myComponent}}`)).toEqual([]); + }); test('mustache missing, no args', function () { let findDependencies = configure({ staticComponents: true, From bef5fa7e1b224de46686383304a428beb565c413 Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Thu, 11 Nov 2021 10:53:22 -0800 Subject: [PATCH 2/5] remove debuggers --- packages/compat/src/resolver-transform.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/compat/src/resolver-transform.ts b/packages/compat/src/resolver-transform.ts index 3cc39c79d..a96344b28 100644 --- a/packages/compat/src/resolver-transform.ts +++ b/packages/compat/src/resolver-transform.ts @@ -64,9 +64,6 @@ export function makeResolverTransform(resolver: Resolver) { if (node.path.type !== 'PathExpression') { return; } - if (node.path.original.includes('liquidif')) { - debugger; - } if (node.path.this === true) { return; } @@ -83,9 +80,6 @@ export function makeResolverTransform(resolver: Resolver) { if (node.path.type !== 'PathExpression') { return; } - if (node.path.original.includes('liquidif')) { - debugger; - } if (scopeStack.inScope(node.path.parts[0])) { return; } From bf424616e2aea2b8cdda1fbd89db36256b44b639 Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Thu, 11 Nov 2021 10:59:50 -0800 Subject: [PATCH 3/5] adding guard --- packages/compat/src/resolver-transform.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compat/src/resolver-transform.ts b/packages/compat/src/resolver-transform.ts index a96344b28..a179892c3 100644 --- a/packages/compat/src/resolver-transform.ts +++ b/packages/compat/src/resolver-transform.ts @@ -28,7 +28,7 @@ export function makeResolverTransform(resolver: Resolver) { if (scopeStack.inScope(node.path.parts[0])) { return; } - if (node.path.head.type === 'ThisHead') { + if (node.path.head && node.path.head.type === 'ThisHead') { return; } if (node.path.parts.length > 1) { From c8911339a75d443755c870ef4df26d4e7e48fcc2 Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Thu, 11 Nov 2021 12:04:24 -0800 Subject: [PATCH 4/5] use this boolean check --- packages/compat/src/resolver-transform.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/compat/src/resolver-transform.ts b/packages/compat/src/resolver-transform.ts index a179892c3..f0e7c0daa 100644 --- a/packages/compat/src/resolver-transform.ts +++ b/packages/compat/src/resolver-transform.ts @@ -28,7 +28,7 @@ export function makeResolverTransform(resolver: Resolver) { if (scopeStack.inScope(node.path.parts[0])) { return; } - if (node.path.head && node.path.head.type === 'ThisHead') { + if (node.path.this === true) { return; } if (node.path.parts.length > 1) { @@ -83,6 +83,9 @@ export function makeResolverTransform(resolver: Resolver) { if (scopeStack.inScope(node.path.parts[0])) { return; } + if (node.path.this === true) { + return; + } if (node.path.parts.length > 1) { // paths with a dot in them (which therefore split into more than // one "part") are classically understood by ember to be contextual From a5e1027fd254b4afa4778d1f6670aa9127855bfe Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Thu, 11 Nov 2021 13:26:27 -0700 Subject: [PATCH 5/5] Update packages/compat/tests/resolver.test.ts Co-authored-by: Robert Jackson --- packages/compat/tests/resolver.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compat/tests/resolver.test.ts b/packages/compat/tests/resolver.test.ts index 2032bed6e..f30f94f2b 100644 --- a/packages/compat/tests/resolver.test.ts +++ b/packages/compat/tests/resolver.test.ts @@ -476,9 +476,9 @@ describe('compat-resolver', function () { let findDependencies = configure({ staticHelpers: true }); expect(findDependencies('templates/application.hbs', `{{(this.myHelper 42)}}`)).toEqual([]); }); - test('class defined component not failing if there is no arguments', function () { + test('helper defined in component not failing if there is no arguments', function () { let findDependencies = configure({ staticComponents: true, staticHelpers: true }); - expect(findDependencies('templates/application.hbs', `{{this.myComponent}}`)).toEqual([]); + expect(findDependencies('templates/application.hbs', `{{#if (this.myHelper)}}{{/if}}`)).toEqual([]); }); test('class defined component not failing if there is a block', function () { let findDependencies = configure({ staticComponents: true, staticHelpers: true });