Skip to content

Commit

Permalink
fix: array notation detection, close #482
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 31, 2021
1 parent 57d87a4 commit b732dd7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
6 changes: 3 additions & 3 deletions examples/by-features/collections/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- array -->
<p>{{ $t('errors[0]') }}</p>
<!-- object in array -->
<p>{{ $t('errors[1].internal1') }}</p>
<p>{{ $t('errors.1.internal1') }}</p>
<!-- array in array -->
<p>{{ $t('errors[2][0]') }}</p>
</div>
Expand All @@ -22,10 +22,10 @@ export default {
}),
computed: {
foobar () {
foobar() {
return this.$t('nested.foo.bar')
},
exists () {
exists() {
return this.$te('nested.foo.bar')
},
},
Expand Down
2 changes: 2 additions & 0 deletions examples/by-features/extractions/SavedBoards.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!-- Ported from https://raw.githubusercontent.com/pepf/retrospectify/master/src/components/SavedBoards.vue -->

<template>
<div class="sidebar-component">
<transition name="slide">
Expand Down Expand Up @@ -39,6 +40,7 @@
</template>

<script>
/* eslint-disable */
import bus from '../bus.js'
export default {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@types/json-stable-stringify": "^1.0.32",
"@types/json5": "^2.2.0",
"@types/lodash": "^4.14.168",
"@types/micromatch": "^4.0.1",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.37",
"@types/qs": "^6.9.6",
Expand Down
9 changes: 6 additions & 3 deletions src/core/Analyst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fs from 'fs'
import { workspace, Range, Location, TextDocument, Uri, EventEmitter } from 'vscode'
// @ts-ignore
import { glob } from 'glob-gitignore'
// @ts-ignore
import micromatch from 'micromatch'
// @ts-ignore
import parseGitIgnore from 'parse-gitignore'
Expand Down Expand Up @@ -145,6 +144,10 @@ export class Analyst {
return new Location(document.uri, range)
}

static normalizeKey(key: string) {
return key.replace(/\[(.*)\]/g, '.$1')
}

static async analyzeUsage(useCache = true): Promise<UsageReport> {
const occurrences = await this.getAllOccurrences(undefined, useCache)
const usages: KeyUsage[] = _(occurrences)
Expand All @@ -154,9 +157,9 @@ export class Analyst {
.value()

// all the keys you have
const allKeys = CurrentFile.loader.keys
const allKeys = CurrentFile.loader.keys.map(i => this.normalizeKey(i))
// keys occur in your code
const inUseKeys = uniq([...usages.map(i => i.keypath), ...Config.keysInUse])
const inUseKeys = uniq([...usages.map(i => i.keypath), ...Config.keysInUse].map(i => this.normalizeKey(i)))

// keys in use
const activeKeys = inUseKeys.filter(i => allKeys.includes(i))
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,11 @@
resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a"
integrity sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA==

"@types/braces@*":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/braces/-/braces-3.0.0.tgz#7da1c0d44ff1c7eb660a36ec078ea61ba7eb42cb"
integrity sha512-TbH79tcyi9FHwbyboOKeRachRq63mSuWYXOflsNO9ZyE5ClQ/JaozNKl+aWUq87qPNsXasXxi2AbgfwIJ+8GQw==

"@types/chai-jest-snapshot@^1.3.6":
version "1.3.6"
resolved "https://registry.yarnpkg.com/@types/chai-jest-snapshot/-/chai-jest-snapshot-1.3.6.tgz#d4d05f4f228ae901e4b3e7599fa10b76f8a6662e"
Expand Down Expand Up @@ -1041,6 +1046,13 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.168.tgz#fe24632e79b7ade3f132891afff86caa5e5ce008"
integrity sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q==

"@types/micromatch@^4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/micromatch/-/micromatch-4.0.1.tgz#9381449dd659fc3823fd2a4190ceacc985083bc7"
integrity sha512-my6fLBvpY70KattTNzYOK6KU1oR1+UCz9ug/JbcF5UrEmeCt9P7DV2t7L8+t18mMPINqGQCE4O8PLOPbI84gxw==
dependencies:
"@types/braces" "*"

"@types/minimist@^1.2.0":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
Expand Down

0 comments on commit b732dd7

Please sign in to comment.