Skip to content

Commit 4b01d1e

Browse files
authored
Turbopack: omit empty source map when code starts with a new line (#77734)
### What? SourceMaps contain some unnecessary sections than can be avoided.
1 parent b541853 commit 4b01d1e

File tree

78 files changed

+76
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+76
-257
lines changed

test/e2e/app-dir/scss/compilation-and-prefixing/compilation-and-prefixing.test.ts

-24
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@ describe.each([
106106
"line": 1,
107107
},
108108
},
109-
{
110-
"map": {
111-
"mappings": "A",
112-
"names": [],
113-
"sources": [],
114-
"version": 3,
115-
},
116-
"offset": {
117-
"column": 91,
118-
"line": 1,
119-
},
120-
},
121109
],
122110
"version": 3,
123111
}
@@ -143,18 +131,6 @@ describe.each([
143131
"line": 1,
144132
},
145133
},
146-
{
147-
"map": {
148-
"mappings": "A",
149-
"names": [],
150-
"sources": [],
151-
"version": 3,
152-
},
153-
"offset": {
154-
"column": 91,
155-
"line": 1,
156-
},
157-
},
158134
],
159135
"version": 3,
160136
}

test/integration/css/test/css-compilation.test.js

-24
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,6 @@ module.exports = {
158158
"line": 1,
159159
},
160160
},
161-
{
162-
"map": {
163-
"mappings": "A",
164-
"names": [],
165-
"sources": [],
166-
"version": 3,
167-
},
168-
"offset": {
169-
"column": 264,
170-
"line": 1,
171-
},
172-
},
173161
],
174162
"version": 3,
175163
}
@@ -216,18 +204,6 @@ module.exports = {
216204
"line": 1,
217205
},
218206
},
219-
{
220-
"map": {
221-
"mappings": "A",
222-
"names": [],
223-
"sources": [],
224-
"version": 3,
225-
},
226-
"offset": {
227-
"column": 264,
228-
"line": 1,
229-
},
230-
},
231207
],
232208
"version": 3,
233209
}

turbopack/crates/turbopack-core/src/code_builder.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,13 @@ impl Code {
187187
}
188188
last_byte_pos = *byte_pos;
189189

190-
if pos.column != 0 || map.is_some() {
191-
sections.push((pos, map.clone().unwrap_or_else(SourceMap::empty_rope)))
190+
if let Some(map) = map {
191+
sections.push((pos, map.clone()))
192+
} else {
193+
// We don't need an empty source map when column is 0 or the next char is a newline.
194+
if pos.column != 0 && read.fill_buf()?.first().is_some_and(|&b| b != b'\n') {
195+
sections.push((pos, SourceMap::empty_rope()));
196+
}
192197
}
193198
}
194199

turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/4c35f_tests_snapshot_css_absolute-uri-import_input_withduplicateurl_css_b7298ed4._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/4e721_crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_b44448e2._.css.map

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/b1abf_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_css_b7298ed4._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/b1abf_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_other_css_b7298ed4._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_0c8b8533._.css.map

+1-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/output/b1abf_turbopack-tests_tests_snapshot_css_chained-attributes_input_a_css_43ef0703._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/output/b1abf_turbopack-tests_tests_snapshot_css_chained-attributes_input_b_css_5e695b86._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/output/b1abf_turbopack-tests_tests_snapshot_css_chained-attributes_input_c_css_50ab7d84._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/output/b1abf_turbopack-tests_tests_snapshot_css_chained-attributes_input_c_css_ed320740._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/output/b1abf_turbopack-tests_tests_snapshot_css_chained-attributes_input_style_css_b7298ed4._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/css-legacy-nesting/output/b1abf_turbopack-tests_tests_snapshot_css_css-legacy-nesting_input_style_da464693.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/css-modules/output/b1abf_turbopack-tests_tests_snapshot_css_css-modules_input_style_module_76a2527b.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/css/output/08d19_foo_style_css_b7298ed4._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/css/output/08d19_foo_style_module_css_b7298ed4._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/css/output/4e721_crates_turbopack-tests_tests_snapshot_css_css_input_imported_css_b7298ed4._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/css/css/output/4e721_crates_turbopack-tests_tests_snapshot_css_css_input_imported_css_d740de60._.single.css.map

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)