Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

VueLexer with a custom function list does not use the configured functions when parsing the script block of Vue SFC files #599

Open
leokolezhuk opened this issue Jun 10, 2022 · 1 comment

Comments

@leokolezhuk
Copy link

馃悰 Bug Report

When using Vue SFC files with a custom VueLexer configuration specifying an array of supporting functions, the Vue Lexer does not look up the specified functions in the <script> block, but only default functions of the JavascriptLexer.

I believe it happens because the JavascriptLexer instance that parses the <script> block does not have the custom functions passed to its constructor:
https://github.com/i18next/i18next-parser/blob/master/src/lexers/vue-lexer.js#L15

To Reproduce

  • Use a vue SFC file as below
  • Use custom Vue lexer configuration, that specifies extra functions (['t', '$t']).
<template>
<div>{{ $t('key1') }}</div>
</template>

<script>

export default {
  data(){
	return {
		key2: this.$t('key2'),
		key3: this.i18n.t('key3')
	}
  },
});
</script>

This is my VueLexer and JavascriptLexer configs:

const vueLexerConfig = {
  lexer: 'VueLexer',
  functions: ['t', '$t']
};
const javaScriptLexerConfig = {
  lexer: 'JavascriptLexer',
  functions: ['t', '$t']
};

...

 lexers: {
    hbs: ['HandlebarsLexer'],
    handlebars: ['HandlebarsLexer'],
    htm: ['HTMLLexer'],
    html: ['HTMLLexer'],
    mjs: [javaScriptLexerConfig],
    js: [javaScriptLexerConfig], 
    ts: [javaScriptLexerConfig],
    vue: [vueLexerConfig],
    jsx: [javaScriptLexerConfig],
    tsx: [javaScriptLexerConfig],
    default: [javaScriptLexerConfig]
  },

Expected behavior

All 3 keys - key1, key2, key3 are extracted to the locale json files.

Actual behavior

Only keys 'key1', 'key3' are extracted.

Your Environment

  • runtime version:
    node - v16.15.1,
    i18next-parser - 6.4.0
@Zikoat
Copy link

Zikoat commented Dec 2, 2022

Duplicate: #262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants