Skip to content

Commit

Permalink
fix: if template content no change it should not compile
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Aug 28, 2022
1 parent 51eca3c commit b0a2096
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/vue-language-core/src/sourceFile.ts
@@ -1,5 +1,5 @@
import { SFCBlock, SFCParseResult, SFCScriptBlock, SFCStyleBlock, SFCTemplateBlock } from '@vue/compiler-sfc';
import { computed, ComputedRef, reactive, shallowRef as ref } from '@vue/reactivity';
import { computed, ComputedRef, reactive, shallowRef as ref, pauseTracking, resetTracking } from '@vue/reactivity';
import { EmbeddedFileMappingData, TeleportMappingData, VueCompilerOptions, _VueCompilerOptions } from './types';
import { EmbeddedFileSourceMap, Teleport } from './utils/sourceMaps';

Expand Down Expand Up @@ -169,18 +169,29 @@ export function createSourceFile(

if (sfc.template) {

pauseTracking();
// don't tracking
const newSnapshot = snapshot.value;
const templateOffset = sfc.template.startTagEnd;
resetTracking();

// tracking
sfc.template.content;

// incremental update
if (compiledSFCTemplateCache?.plugin.updateSFCTemplate) {
const change = snapshot.value.getChangeRange(compiledSFCTemplateCache.snapshot);

const change = newSnapshot.getChangeRange(compiledSFCTemplateCache.snapshot);

if (change) {
const newText = snapshot.value.getText(change.span.start, change.span.start + change.newLength);
const newText = newSnapshot.getText(change.span.start, change.span.start + change.newLength);
const newResult = compiledSFCTemplateCache.plugin.updateSFCTemplate(compiledSFCTemplateCache.result, {
start: change.span.start - sfc.template.startTagEnd,
end: change.span.start + change.span.length - sfc.template.startTagEnd,
start: change.span.start - templateOffset,
end: change.span.start + change.span.length - templateOffset,
newText,
});
if (newResult) {
compiledSFCTemplateCache.snapshot = snapshot.value;
compiledSFCTemplateCache.snapshot = newSnapshot;
compiledSFCTemplateCache.result = newResult;
return {
errors: [],
Expand Down Expand Up @@ -214,7 +225,7 @@ export function createSourceFile(

if (result && !errors.length && !warnings.length) {
compiledSFCTemplateCache = {
snapshot: snapshot.value,
snapshot: newSnapshot,
result: result,
plugin,
};
Expand Down

0 comments on commit b0a2096

Please sign in to comment.