{"version":3,"file":"index.cjs","names":["plugin: IPlugin","properties: (Property | Expression)[]"],"sources":["../src/index.ts"],"sourcesContent":["import type { IPlugin, JsepInstance, Expression, HookEnv } from 'nc-jsep/types';\n\nconst OCURLY_CODE = 123; // {\nconst CCURLY_CODE = 125; // }\nconst OBJECT_EXP = 'ObjectExpression';\nconst PROPERTY = 'Property';\n\ninterface Property {\n  type: string;\n  computed: boolean;\n  key: Expression;\n  value: Expression;\n  shorthand: boolean;\n}\n\nconst plugin: IPlugin = {\n  name: 'object',\n\n  init(jsep: JsepInstance) {\n    // Object literal support\n    function gobbleObjectExpression(this: JsepInstance, env: HookEnv) {\n      if (this.code === OCURLY_CODE) {\n        this.index++;\n        const properties: (Property | Expression)[] = [];\n\n        while (!isNaN(this.code)) {\n          this.gobbleSpaces();\n          if (this.code === CCURLY_CODE) {\n            this.index++;\n            env.node = this.gobbleTokenProperty({\n              type: OBJECT_EXP,\n              properties,\n            });\n            return;\n          }\n\n          // Note: using gobbleExpression instead of gobbleToken to support object destructuring\n          const key = this.gobbleExpression();\n          if (!key) {\n            break; // missing }\n          }\n\n          this.gobbleSpaces();\n          if (key.type === jsep.IDENTIFIER && (this.code === jsep.COMMA_CODE || this.code === CCURLY_CODE)) {\n            // property value shorthand\n            properties.push({\n              type: PROPERTY,\n              computed: false,\n              key,\n              value: key,\n              shorthand: true,\n            });\n          }\n          else if (this.code === jsep.COLON_CODE) {\n            this.index++;\n            const value = this.gobbleExpression();\n\n            if (!value) {\n              this.throwError('unexpected object property');\n            }\n            const computed = key.type === jsep.ARRAY_EXP;\n            const keyExpr = key as Expression & { elements?: Expression[] };\n            properties.push({\n              type: PROPERTY,\n              computed,\n              key: computed\n                ? keyExpr.elements![0]\n                : key,\n              value: value,\n              shorthand: false,\n            });\n            this.gobbleSpaces();\n          }\n          else if (key) {\n            // spread, assignment (object destructuring with defaults), etc.\n            properties.push(key);\n          }\n\n          if (this.code === jsep.COMMA_CODE) {\n            this.index++;\n          }\n        }\n        this.throwError('missing }');\n      }\n    }\n\n    jsep.hooks.add('gobble-token', gobbleObjectExpression);\n  }\n};\n\nexport default plugin;\n"],"mappings":";;AAEA,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,aAAa;AACnB,MAAM,WAAW;AAUjB,MAAMA,SAAkB;CACtB,MAAM;CAEN,KAAK,MAAoB;EAEvB,SAAS,uBAA2C,KAAc;AAChE,OAAI,KAAK,SAAS,aAAa;AAC7B,SAAK;IACL,MAAMC,aAAwC,EAAE;AAEhD,WAAO,CAAC,MAAM,KAAK,KAAK,EAAE;AACxB,UAAK,cAAc;AACnB,SAAI,KAAK,SAAS,aAAa;AAC7B,WAAK;AACL,UAAI,OAAO,KAAK,oBAAoB;OAClC,MAAM;OACN;OACD,CAAC;AACF;;KAIF,MAAM,MAAM,KAAK,kBAAkB;AACnC,SAAI,CAAC,IACH;AAGF,UAAK,cAAc;AACnB,SAAI,IAAI,SAAS,KAAK,eAAe,KAAK,SAAS,KAAK,cAAc,KAAK,SAAS,aAElF,YAAW,KAAK;MACd,MAAM;MACN,UAAU;MACV;MACA,OAAO;MACP,WAAW;MACZ,CAAC;cAEK,KAAK,SAAS,KAAK,YAAY;AACtC,WAAK;MACL,MAAM,QAAQ,KAAK,kBAAkB;AAErC,UAAI,CAAC,MACH,MAAK,WAAW,6BAA6B;MAE/C,MAAM,WAAW,IAAI,SAAS,KAAK;MACnC,MAAM,UAAU;AAChB,iBAAW,KAAK;OACd,MAAM;OACN;OACA,KAAK,WACD,QAAQ,SAAU,KAClB;OACG;OACP,WAAW;OACZ,CAAC;AACF,WAAK,cAAc;gBAEZ,IAEP,YAAW,KAAK,IAAI;AAGtB,SAAI,KAAK,SAAS,KAAK,WACrB,MAAK;;AAGT,SAAK,WAAW,YAAY;;;AAIhC,OAAK,MAAM,IAAI,gBAAgB,uBAAuB;;CAEzD;AAED,kBAAe"}