简体   繁体   English

如何修复意外的令牌解析错误?

[英]how to fix unexpected token parsing error?

The arrow works for me all time but i get an error now Parsing error: Unexpected token => I tried checking the syntax and bracket and yeah, I dint miss any brackets.箭头一直对我有用,但现在我得到一个错误Parsing error: Unexpected token =>我尝试检查语法和括号,是的,我错过了任何括号。

Code:代码:

const functions = require("firebase-functions");

const Filter = require("bad-words");

const admin = require("firebase-admin");
admin.initializeApp();

const db = admin.firestore();

exports.detectEvilUsers = functions.firestore
  .document("messages/{msgId}")
  .onCreate(async (doc, ctx) => {
    const filter = new Filter();
    const { text, uid } = doc.data();

    if (filter.isProfane(text)) {
      const cleaned = filter.clean(text);
      await doc.ref.update({
        text: "I got banned for lifetime for using voilated words",
      });

      await db.collection("banned").doc(uid).set({});
    }
  });

Error:错误:

Parsing error: Unexpected token =>解析错误:意外的令牌 =>

And If try to change it to normal function(){} call, like this如果尝试将其更改为正常的 function(){} 调用,就像这样

exports.detectEvilUsers = functions.firestore
  .document("messages/{msgId}")
  .onCreate(async function(doc, ctx)  {
        const filter = new Filter();
        const { text, uid } = doc.data();
    ....
    ....
    ....
    }

It gives me Parsing error:unexpected token function它给了我Parsing error:unexpected token function

Eslin.json file: { "parser": "babel-eslint", "plugins": [ "babel" ], "extends": [ "plugin:prettier/recommended", "plugin:react/recommended" ], "env": { "browser": true, "es6": true, "jest": true }, "parserOptions": { "ecmaVersion": 2018, "sourceType": "module", "ecmaFeatures": { "jsx": true } }, "rules": { "curly": "error", "eqeqeq": "error", "guard-for-in": "error", "no-extend-native": "error", "complexity": [ "error", 200 ], "max-depth": [ "error", 5 ], "max-params": [ "error", 12 ], "max-statements": [ "error", 200 ], "no-caller": "error", "no-irregular-whitespace": "error", "no-new": "error", "no-undef": "error", "no-unused-vars": "error", "no-global-assign": "error", "react/prop-types": "off", "babel/semi": 1 } } Eslin.json 文件: { "parser": "babel-eslint", "plugins": [ "babel" ], "extends": [ "plugin:prettier/recommended", "plugin:react/recommended" ], "env": { "browser": true, "es6": true, "jest": true }, "parserOptions": { "ecmaVersion": 2018, "sourceType": "module", "ecmaFeatures": { "jsx": true } }, "rules": { "curly": "error", "eqeqeq": "error", "guard-for-in": "error", "no-extend-native": "error", "complexity": [ "error", 200 ], "max-depth": [ "error", 5 ], "max-params": [ "error", 12 ], "max-statements": [ "error", 200 ], "no-caller": "error", "no-irregular-whitespace": "error", "no-new": "error", "no-undef": "error", "no-unused-vars": "error", "no-global-assign": "error", "react/prop-types": "off", "babel/semi": 1 } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM