-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support <script setup> in Vue 2.7 #483
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
da15003
feat: support <script setup> in Vue 2.7
FelixGraf 8558c4d
refactor: remove unnecessary bindingMetadata
FelixGraf 728d374
refactor: remove unnecessary refTransform
FelixGraf 87d27e2
feat: add setup to generateSourceMap
FelixGraf 23e3fc5
chore: update Vue dependencies
FelixGraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<div> | ||
<button @click="increase">Count: {{ num }}</button> | ||
<Basic /> | ||
<span>{{ msg }}</span> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref } from 'vue' | ||
import Basic from './Basic.vue' | ||
|
||
const num = ref(5) | ||
const greet = () => console.log('greet') | ||
const increase = () => { | ||
greet() | ||
num.value++ | ||
} | ||
const msg = 'hello world' | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { SourceMapGenerator, SourceMapConsumer } = require('source-map') | ||
|
||
// based on @vue/compiler-sfc mapLines | ||
module.exports = function mapLines(oldMap, newMap) { | ||
if (!oldMap) return newMap | ||
if (!newMap) return oldMap | ||
|
||
const oldMapConsumer = new SourceMapConsumer(oldMap) | ||
const newMapConsumer = new SourceMapConsumer(newMap) | ||
const mergedMapGenerator = new SourceMapGenerator() | ||
|
||
newMapConsumer.eachMapping(m => { | ||
if (m.originalLine == null) { | ||
return | ||
} | ||
|
||
const origPosInOldMap = oldMapConsumer.originalPositionFor({ | ||
line: m.originalLine, | ||
column: m.originalColumn | ||
}) | ||
|
||
if (origPosInOldMap.source == null) { | ||
return | ||
} | ||
|
||
mergedMapGenerator.addMapping({ | ||
generated: { | ||
line: m.generatedLine, | ||
column: m.generatedColumn | ||
}, | ||
original: { | ||
line: origPosInOldMap.line, // map line | ||
// use current column, since the oldMap produced by @vue/compiler-sfc | ||
// does not | ||
column: m.originalColumn | ||
}, | ||
source: origPosInOldMap.source, | ||
name: origPosInOldMap.name | ||
}) | ||
}) | ||
|
||
// source-map's type definition is incomplete | ||
const generator = mergedMapGenerator | ||
oldMapConsumer.sources.forEach(sourceFile => { | ||
generator._sources.add(sourceFile) | ||
const sourceContent = oldMapConsumer.sourceContentFor(sourceFile) | ||
if (sourceContent != null) { | ||
mergedMapGenerator.setSourceContent(sourceFile, sourceContent) | ||
} | ||
}) | ||
|
||
generator._sourceRoot = oldMap.sourceRoot | ||
generator._file = oldMap.file | ||
return generator.toJSON() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vue/compiler-sfc
isn't listed as a dependency of this package, so this import is unsound. There is a similar existing issue for thevue-template-compiler
import as well (which should probably have been listed as an optional peer dependency).I know there are other changes in vue 2.7 that make vue-template-compiler no longer necessary, so there might be larger refactors in the works for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't
@vue/compiler-sfc
Vue 3 only? I'm really surprised this works at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also looks like tests are failing - you may need to update a snapshot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, they now have a v2.7 for this module: https://www.npmjs.com/package/@vue/compiler-sfc