From c747d286cdbd25dbbfbf5a0eada5246476d958cc Mon Sep 17 00:00:00 2001 From: Olivier Pinon Date: Thu, 24 Oct 2024 15:39:56 +0200 Subject: [PATCH] Move sourcemap declaration at the top --- compiler-core/src/javascript.rs | 8 ++++---- ...ourcemaps__sourcemap_function_definition.snap | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler-core/src/javascript.rs b/compiler-core/src/javascript.rs index 44bb69a0a0a..55edaf9b319 100644 --- a/compiler-core/src/javascript.rs +++ b/compiler-core/src/javascript.rs @@ -198,28 +198,28 @@ impl<'a> Generator<'a> { if imports.is_empty() && statements.is_empty() { Ok(docvec![ + sourcemap_reference, type_reference, "export {}", line(), - sourcemap_reference, ]) } else if imports.is_empty() { statements.push(line()); - Ok(docvec![type_reference, statements, sourcemap_reference]) + Ok(docvec![sourcemap_reference, type_reference, statements]) } else if statements.is_empty() { Ok(docvec![ + sourcemap_reference, type_reference, imports.into_doc(JavaScriptCodegenTarget::JavaScript, self.line_numbers), - sourcemap_reference, ]) } else { Ok(docvec![ + sourcemap_reference, type_reference, imports.into_doc(JavaScriptCodegenTarget::JavaScript, self.line_numbers), line(), statements, line(), - sourcemap_reference, ]) } } diff --git a/compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__sourcemaps__sourcemap_function_definition.snap b/compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__sourcemaps__sourcemap_function_definition.snap index ef750e50fb1..99fde0580f0 100644 --- a/compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__sourcemaps__sourcemap_function_definition.snap +++ b/compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__sourcemaps__sourcemap_function_definition.snap @@ -8,9 +8,9 @@ note: 1 │ fn add_2(x) { │ ^ This code │ - ┌─ generated.js:1:1 + ┌─ generated.js:2:1 │ -1 │ function add_2(x) { +2 │ function add_2(x) { │ ^ Gets mapped to this --- @@ -20,9 +20,9 @@ note: 2 │ x + 2 │ ^ This code │ - ┌─ generated.js:2:3 + ┌─ generated.js:3:3 │ -2 │ return x + 2; +3 │ return x + 2; │ ^ Gets mapped to this --- @@ -32,9 +32,9 @@ note: 2 │ x + 2 │ ^ This code │ - ┌─ generated.js:2:10 + ┌─ generated.js:3:10 │ -2 │ return x + 2; +3 │ return x + 2; │ ^ Gets mapped to this --- @@ -44,7 +44,7 @@ note: 2 │ x + 2 │ ^ This code │ - ┌─ generated.js:2:14 + ┌─ generated.js:3:14 │ -2 │ return x + 2; +3 │ return x + 2; │ ^ Gets mapped to this