Skip to content

Commit 8696fea

Browse files
committed
fix issues regarding positions in HTML
1 parent e116804 commit 8696fea

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

src/preprocess.js

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ export const preprocess = (text, filename) => {
130130
let processedMarkup;
131131
let moduleExt = 'js';
132132
let instanceExt = 'js';
133+
let moduleEndLine;
134+
let processedModuleLineOffset;
135+
let instanceEndLine;
136+
let processedInstanceLineOffset;
133137
try {
134138
// run preprocessor if present
135139
if (processor_options.svelte_preprocess) {
@@ -142,8 +146,6 @@ export const preprocess = (text, filename) => {
142146
state.mappings = decode(result.mappings);
143147
}
144148

145-
processedMarkup = result.markup;
146-
147149
if (result.module) {
148150
processedModule = result.module;
149151
moduleExt = result.module.ext;
@@ -155,6 +157,8 @@ export const preprocess = (text, filename) => {
155157

156158
processedStyle = result.style;
157159

160+
processedMarkup = result.markup;
161+
158162
processor_options.named_blocks = true;
159163
}
160164
}
@@ -163,10 +167,10 @@ export const preprocess = (text, filename) => {
163167
if (processedResult) {
164168
const { html, css, instance, module } = result.ast;
165169

166-
let styleDiff = processedStyle ? processedStyle.diff : 0;
167-
let markupDiff = processedMarkup ? processedMarkup.diff : 0;
168170
let moduleDiff = processedModule ? processedModule.diff : 0;
169171
let instanceDiff = processedInstance ? processedInstance.diff : 0;
172+
let styleDiff = processedStyle ? processedStyle.diff : 0;
173+
let markupDiff = processedMarkup ? processedMarkup.diff : 0;
170174

171175
let modulePreOffset = 0;
172176
let modulePostOffset = 0;
@@ -201,6 +205,8 @@ export const preprocess = (text, filename) => {
201205
}
202206

203207
if (module && processedModule) {
208+
moduleEndLine = module.content.loc.end.line;
209+
processedModuleLineOffset = processedModule.ast.loc.end.line - moduleEndLine;
204210
module.content.body = processedModule.ast.body;
205211

206212
module.start += modulePreOffset;
@@ -211,6 +217,8 @@ export const preprocess = (text, filename) => {
211217
}
212218

213219
if (instance && processedInstance) {
220+
instanceEndLine = instance.content.loc.end.line;
221+
processedInstanceLineOffset = processedInstance.ast.loc.end.line - instanceEndLine;
214222
instance.content.body = processedInstance.ast.body;
215223

216224
instance.start += instancePreOffset;
@@ -240,15 +248,26 @@ export const preprocess = (text, filename) => {
240248
state.var_names = new Set(vars.map(v => v.name));
241249

242250
// convert warnings to linting messages
243-
state.messages = (processor_options.ignore_warnings ? warnings.filter(warning => !processor_options.ignore_warnings(warning)) : warnings).map(({ code, message, start, end }) => ({
244-
ruleId: code,
245-
severity: 1,
246-
message,
247-
line: start && start.line,
248-
column: start && start.column + 1,
249-
endLine: end && end.line,
250-
endColumn: end && end.column + 1,
251-
}));
251+
state.messages = (processor_options.ignore_warnings ? warnings.filter(warning => !processor_options.ignore_warnings(warning)) : warnings).map(({ code, message, start, end }) => {
252+
let fixLine = 0;
253+
254+
if (processedInstanceLineOffset && start && start.line > instanceEndLine ) {
255+
fixLine += processedInstanceLineOffset;
256+
}
257+
258+
if (processedModuleLineOffset && start && start.line > moduleEndLine ) {
259+
fixLine += processedModuleLineOffset;
260+
}
261+
return {
262+
ruleId: code,
263+
severity: 1,
264+
message,
265+
line: start && start.line + fixLine,
266+
column: start && start.column + 1,
267+
endLine: end && end.line + fixLine,
268+
endColumn: end && end.column + 1,
269+
}
270+
});
252271

253272
// build strings that we can send along to ESLint to get the remaining messages
254273

0 commit comments

Comments
 (0)