8000 Fix decorator indent · vuejs/eslint-plugin-vue@5c27868 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit 5c27868

Browse files
committed
Fix decorator indent
1 parent 8136488 commit 5c27868

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

lib/utils/indent-common.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ module.exports.defineVisitor = function create(
211211
defaultOptions
212212
)
213213
const sourceCode = context.getSourceCode()
214+
/**
215+
* @typedef { { baseToken: Token | null, offset: number, baseline: boolean, expectedIndent: number | undefined } } OffsetData
216+
*/
217+
/** @type {Map<Token|null, OffsetData>} */
214218
const offsets = new Map()
215219
const ignoreTokens = new Set()
216220

@@ -227,7 +231,7 @@ module.exports.defineVisitor = function create(
227231
}
228232
if (Array.isArray(token)) {
229233
for (const t of token) {
230-
if (t === baseToken) continue
234+
if (!t || t === baseToken) continue
231235
offsets.set(t, {
232236
baseToken,
233237
10000 offset,
@@ -260,10 +264,16 @@ module.exports.defineVisitor = function create(
260264
return
261265
}
262266

263-
setOffset(token, offsetData.offset, offsetData.baseToken)
267+
setOffset(
268+
token,
269+
offsetData.offset,
270+
/** @type {Token} */ (offsetData.baseToken)
271+
)
264272
if (offsetData.baseline) {
265273
setBaseline(token)
266274
}
275+
const o = /** @type {OffsetData} */ (offsets.get(token))
276+
o.expectedIndent = offsetData.expectedIndent
267277
}
268278

269279
/**
@@ -722,7 +732,7 @@ module.exports.defineVisitor = function create(
722732
* Validate the given token with the pre-calculated expected indentation.
723733
* @param {Token} token The token to validate.
724734
* @param {number} expectedIndent The expected indentation.
725-
* @param {number[]} [optionalExpectedIndents] The optional expected indentation.
735+
* @param {[number, number?]} [optionalExpectedIndents] The optional expected indentation.
726736
* @returns {void}
727737
*/
728738
function validateCore(token, expectedIndent, optionalExpectedIndents) {
@@ -786,8 +796,8 @@ module.exports.defineVisitor = function create(
786796
* Get the expected indent of comments.
787797
* @param {Token} nextToken The next token of comments.
788798
* @param {number} nextExpectedIndent The expected indent of the next token.
789-
* @param {number} lastExpectedIndent The expected indent of the last token.
790-
* @returns {number[]}
799+
* @param {number|undefined} lastExpectedIndent The expected indent of the last token.
800+
* @returns {[number, number?]}
791801
*/
792802
function getCommentExpectedIndents(
793803
nextToken,
@@ -873,8 +883,8 @@ module.exports.defineVisitor = function create(
873883
baseline.add(token)
874884
} else if (baseline.has(offsetInfo.baseToken)) {
875885
// The base token is a baseline token on this line, so inherit it.
876-
offsetInfo.expectedIndent = offsets.get(
877-
offsetInfo.baseToken
886+
offsetInfo.expectedIndent = /** @type {OffsetData} */ (
887+
offsets.get(offsetInfo.baseToken)
878888
).expectedIndent
879889
baseline.add(token)
880890
} else {

lib/utils/indent-ts.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,14 @@ function defineVisitor({
11961196
)
11971197
setOffset(startParentToken, 0, atToken)
11981198
} else {
1199-
const startParentToken = tokenStore.getFirstToken(parent)
1199+
const startParentToken = tokenStore.getFirstToken(
1200+
parent.parent &&
1201+
(parent.parent.type === 'ExportDefaultDeclaration' ||
1202+
parent.parent.type === 'ExportNamedDeclaration') &&
1203+
node.range[0] < parent.parent.range[0]
1204+
? parent.parent
1205+
: parent
1206+
)
12001207
copyOffset(atToken, startParentToken)
12011208
}
12021209
} else {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--{"parserOptions": {"parser":"@typescript-eslint/parser"}}-->
2+
<script lang="ts">
3+
import {Component, Prop, Vue} from "vue-property-decorator";
4+
5+
@Component
6+
export default class UserComp extends Vue {
7+
private id = "UserComp";
8+
}
9+
</script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--{"parserOptions": {"parser":"@typescript-eslint/parser"}}-->
2+
<script lang="ts">
3+
@
4+
(
5+
d
6+
)
7+
@
8+
(
9+
d
10+
)
11+
.d
12+
export class Foo {
13+
}
14+
</script>

0 commit comments

Comments
 (0)
0