From d586f3a5e6c778f621f2c1fead7fe0f083afde9e Mon Sep 17 00:00:00 2001 From: Sebastian Lorenz Date: Sat, 20 Jul 2024 11:02:13 +0200 Subject: [PATCH 1/3] add support for pure annotations class expressions --- src/index.js | 2 +- test/fixtures/annotate/dynamic-extends/code.js | 8 ++++++++ test/fixtures/annotate/dynamic-extends/output6.js | 7 +++++++ test/fixtures/annotate/dynamic-extends/output7.js | 9 +++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/annotate/dynamic-extends/code.js create mode 100644 test/fixtures/annotate/dynamic-extends/output6.js create mode 100644 test/fixtures/annotate/dynamic-extends/output7.js diff --git a/src/index.js b/src/index.js index 3ac61ad..9f5ba28 100644 --- a/src/index.js +++ b/src/index.js @@ -65,7 +65,7 @@ const isInAssignmentContext = path => { do { ;({ parentPath } = parentPath || path) - if (parentPath.isVariableDeclaration() || parentPath.isAssignmentExpression()) { + if (parentPath.isVariableDeclaration() || parentPath.isAssignmentExpression() || parentPath.isClassDeclaration()) { return true } } while (parentPath !== statement) diff --git a/test/fixtures/annotate/dynamic-extends/code.js b/test/fixtures/annotate/dynamic-extends/code.js new file mode 100644 index 0000000..dea8cd9 --- /dev/null +++ b/test/fixtures/annotate/dynamic-extends/code.js @@ -0,0 +1,8 @@ +const base = bar => + class { + foo() { + return bar + } + } + +class MyClass extends base() {} diff --git a/test/fixtures/annotate/dynamic-extends/output6.js b/test/fixtures/annotate/dynamic-extends/output6.js new file mode 100644 index 0000000..18ece3c --- /dev/null +++ b/test/fixtures/annotate/dynamic-extends/output6.js @@ -0,0 +1,7 @@ +const base = bar => class { + foo() { + return bar; + } +}; + +class MyClass extends /*#__PURE__*/base() {} diff --git a/test/fixtures/annotate/dynamic-extends/output7.js b/test/fixtures/annotate/dynamic-extends/output7.js new file mode 100644 index 0000000..47ae2f0 --- /dev/null +++ b/test/fixtures/annotate/dynamic-extends/output7.js @@ -0,0 +1,9 @@ +const base = bar => class { + foo() { + return bar; + } +}; + +class MyClass extends +/*#__PURE__*/ +base() {} From 4bd79f44497cd5796f3220fe223bb44528037631 Mon Sep 17 00:00:00 2001 From: Sebastian Lorenz Date: Sat, 20 Jul 2024 18:56:38 +0200 Subject: [PATCH 2/3] Update src/index.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mateusz BurzyƄski --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 9f5ba28..8b3dfc3 100644 --- a/src/index.js +++ b/src/index.js @@ -65,7 +65,7 @@ const isInAssignmentContext = path => { do { ;({ parentPath } = parentPath || path) - if (parentPath.isVariableDeclaration() || parentPath.isAssignmentExpression() || parentPath.isClassDeclaration()) { + if (parentPath.isVariableDeclaration() || parentPath.isAssignmentExpression() || parentPath.isClassDeclaration() || parentPath.isClassExpression()) { return true } } while (parentPath !== statement) From b494d946c117962a063fe58295a869eca5efee3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 7 Jan 2025 10:25:09 +0100 Subject: [PATCH 3/3] tweak tests --- .../code.js | 0 .../output.js} | 3 +-- .../annotate/class-expression-dynamic-extends/code.js | 8 ++++++++ .../output.js} | 5 +---- 4 files changed, 10 insertions(+), 6 deletions(-) rename test/fixtures/annotate/{dynamic-extends => class-declaration-dynamic-extends}/code.js (100%) rename test/fixtures/annotate/{dynamic-extends/output6.js => class-declaration-dynamic-extends/output.js} (57%) create mode 100644 test/fixtures/annotate/class-expression-dynamic-extends/code.js rename test/fixtures/annotate/{dynamic-extends/output7.js => class-expression-dynamic-extends/output.js} (53%) diff --git a/test/fixtures/annotate/dynamic-extends/code.js b/test/fixtures/annotate/class-declaration-dynamic-extends/code.js similarity index 100% rename from test/fixtures/annotate/dynamic-extends/code.js rename to test/fixtures/annotate/class-declaration-dynamic-extends/code.js diff --git a/test/fixtures/annotate/dynamic-extends/output6.js b/test/fixtures/annotate/class-declaration-dynamic-extends/output.js similarity index 57% rename from test/fixtures/annotate/dynamic-extends/output6.js rename to test/fixtures/annotate/class-declaration-dynamic-extends/output.js index 18ece3c..d4529c3 100644 --- a/test/fixtures/annotate/dynamic-extends/output6.js +++ b/test/fixtures/annotate/class-declaration-dynamic-extends/output.js @@ -3,5 +3,4 @@ const base = bar => class { return bar; } }; - -class MyClass extends /*#__PURE__*/base() {} +class MyClass extends /*#__PURE__*/base() {} \ No newline at end of file diff --git a/test/fixtures/annotate/class-expression-dynamic-extends/code.js b/test/fixtures/annotate/class-expression-dynamic-extends/code.js new file mode 100644 index 0000000..588cd13 --- /dev/null +++ b/test/fixtures/annotate/class-expression-dynamic-extends/code.js @@ -0,0 +1,8 @@ +const base = bar => + class { + foo() { + return bar + } + } + +const MyClass = class extends base() {} diff --git a/test/fixtures/annotate/dynamic-extends/output7.js b/test/fixtures/annotate/class-expression-dynamic-extends/output.js similarity index 53% rename from test/fixtures/annotate/dynamic-extends/output7.js rename to test/fixtures/annotate/class-expression-dynamic-extends/output.js index 47ae2f0..636f15a 100644 --- a/test/fixtures/annotate/dynamic-extends/output7.js +++ b/test/fixtures/annotate/class-expression-dynamic-extends/output.js @@ -3,7 +3,4 @@ const base = bar => class { return bar; } }; - -class MyClass extends -/*#__PURE__*/ -base() {} +const MyClass = class extends /*#__PURE__*/base() {}; \ No newline at end of file