Skip to content

Commit 5c436ac

Browse files
committed
minor tidy-up - always add sourcemap locations for contextualised expressions
1 parent ecf1413 commit 5c436ac

File tree

5 files changed

+6
-10
lines changed

5 files changed

+6
-10
lines changed

src/generators/Generator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export default class Generator {
4646
}
4747

4848
contextualise ( expression, isEventHandler ) {
49+
this.addSourcemapLocations( expression );
50+
4951
const usedContexts = [];
5052
const dependencies = [];
5153

src/generators/dom/visitors/MustacheTag.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export default {
44
enter ( generator, node ) {
55
const name = generator.current.getUniqueName( 'text' );
66

7-
generator.addSourcemapLocations( node.expression );
87
const { snippet } = generator.contextualise( node.expression );
98

109
generator.current.builders.init.addLine( `var last_${name} = ${snippet}` );

src/generators/dom/visitors/RawMustacheTag.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export default {
44
enter ( generator, node ) {
55
const name = generator.current.getUniqueName( 'raw' );
66

7-
generator.addSourcemapLocations( node.expression );
87
const { snippet } = generator.contextualise( node.expression );
98

109
// we would have used comments here, but the `insertAdjacentHTML` api only

src/generators/dom/visitors/attributes/addComponentAttributes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ export default function addComponentAttributes ( generator, node, local ) {
5757
if ( chunk.type === 'Text' ) {
5858
return JSON.stringify( chunk.data );
5959
} else {
60-
generator.addSourcemapLocations( chunk.expression );
61-
6260
const { dependencies, string } = generator.contextualise( chunk.expression );
6361
dependencies.forEach( dependency => {
6462
if ( !~allDependencies.indexOf( dependency ) ) allDependencies.push( dependency );
@@ -84,7 +82,7 @@ export default function addComponentAttributes ( generator, node, local ) {
8482

8583
const usedContexts = [];
8684
attribute.expression.arguments.forEach( arg => {
87-
const { contexts } = generator.contextualise( arg, true, true );
85+
const { contexts } = generator.contextualise( arg, true );
8886

8987
contexts.forEach( context => {
9088
if ( !~usedContexts.indexOf( context ) ) usedContexts.push( context );

src/generators/dom/visitors/attributes/addElementAttributes.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default function addElementAttributes ( generator, node, local ) {
9696
if ( propertyName ) {
9797
updater = `${local.name}.${propertyName} = ${last};`;
9898
} else {
99-
updater = `${generator.helper( method )}( ${local.name}, '${name}', ${last} );`; // TODO use snippet both times – see note below
99+
updater = `${generator.helper( method )}( ${local.name}, '${name}', ${last} );`;
100100
}
101101

102102
local.init.addLine( updater );
@@ -117,10 +117,8 @@ export default function addElementAttributes ( generator, node, local ) {
117117
if ( chunk.type === 'Text' ) {
118118
return JSON.stringify( chunk.data );
119119
} else {
120-
generator.addSourcemapLocations( chunk.expression );
121-
122-
const { string } = generator.contextualise( chunk.expression ); // TODO use snippet for sourcemap support – need to add a 'copy' feature to MagicString first
123-
return `( ${string} )`;
120+
const { snippet } = generator.contextualise( chunk.expression );
121+
return `( ${snippet} )`;
124122
}
125123
}).join( ' + ' )
126124
);

0 commit comments

Comments
 (0)