Почему мой более красивый пользовательский плагин не работает?

я создаю новое расширение Vscode, используя более красивый собственный плагин для форматирования кода по требованию, весь мой код работает правильно, даже расширение работает правильно, но мой файл плагина, который я описываю здесь, не может печатать значения consol.log, такие как узел и текст, и по этой причине я не могу отформатировать файл, используя свое расширение

красивее-плагин/newplugin.js

      const babelParser = require('@babel/parser');

module.exports = {
    parsers: {
        customJS: {
            parse: (text) => {
                **console.log(" ~ file: newplug.js:7 ~ text:", text)**
                // Directly use @babel/parser
                return babelParser.parse(text, {
                    sourceType: 'module',
                    plugins: [
                        'jsx',
                        'typescript',
                        'classProperties',
                        'javascript' /* any other plugins you want to support */,
                    ],
                });
            },
            astFormat: 'customJS',
            locStart: (node) => node.start,
            locEnd: (node) => node.end,
        },
    },
    printers: {
        customJS: {
            print: (path, options, print) => {
                const node = path.getValue();
                
                **console.log(" ~ file: newplug.js:27 ~ node:", node);**
                
                if (node.type === 'StringLiteral') {
                    node.value = node.value.replace(/"/g, "'");
                    return `'${node.value}'`;
                }
        
                if (node.type === 'ObjectExpression') {
                    console.log(" ~ file: newplug.js:36 ~ node:", node)
                    const properties = path.map.print(print, "properties");
                    return `{\n${properties.join(",\n")}\n}`;
                  }

                return path.call(print);
            },
        },
    },

};

FormateCustomPreitter.js

      import * as prettier from 'prettier';

//formatting custome code which tack options from .prettierrc file and text 
const formatCustomCode = async (text: string) => {
    const configPath = await prettier.resolveConfigFile(__dirname);
    const options = await prettier.resolveConfig(configPath as string);
    console.log(
        ' ~ file: formatWithCustomPrettier.ts:21 ~ formatCustomCode ~ options:',
        options
    );

    return prettier.format(text, {
        ...options,
        parser: 'babel',
    });
};

export default formatCustomCode;

.pritterrc

      {   
    "plugins": ["./src/prettier-plugin/newplug.js"]
}


please provide solution if you have any idea about this 
thank you

0 ответов

Другие вопросы по тегам