Babel

Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,比如Iterator、Generator、Set、Maps、Proxy、Reflect、Symbol、Promise等全局对象,以及一些定义在全局对象上的方法(比如Object.assign)都不会转码。Babel默认不转码的API非常多,详细清单可以查看definitions.js文件

definitions.js文件内容如下:

  1 export default {
  2   builtins: {
  3     Symbol: "symbol",
  4     Promise: "promise",
  5     Map: "map",
  6     WeakMap: "weak-map",
  7     Set: "set",
  8     WeakSet: "weak-set",
  9     Observable: "observable",
 10     setImmediate: "set-immediate",
 11     clearImmediate: "clear-immediate",
 12     asap: "asap",
 13     //parseFloat: "parse-float", // temporary disabled
 14     //parseInt: "parse-int" // temporary disabled
 15   },
 16 
 17   methods: {
 18     Array: {
 19       copyWithin: "array/copy-within",
 20       entries: "array/entries",
 21       every: "array/every",
 22       fill: "array/fill",
 23       filter: "array/filter",
 24       findIndex: "array/find-index",
 25       find: "array/find",
 26       forEach: "array/for-each",
 27       from: "array/from",
 28       includes: "array/includes",
 29       indexOf: "array/index-of",
 30       //isArray: "array/is-array", // temporary disabled
 31       join: "array/join",
 32       keys: "array/keys",
 33       lastIndexOf: "array/last-index-of",
 34       map: "array/map",
 35       of: "array/of",
 36       reduceRight: "array/reduce-right",
 37       reduce: "array/reduce",
 38       some: "array/some",
 39       sort: "array/sort",
 40       splice: "array/splice",
 41       values: "array/values",
 42     },
 43 
 44     JSON: {
 45       stringify: "json/stringify",
 46     },
 47 
 48     Object: {
 49       assign: "object/assign",
 50       create: "object/create",
 51       defineProperties: "object/define-properties",
 52       defineProperty: "object/define-property",
 53       entries: "object/entries",
 54       freeze: "object/freeze",
 55       getOwnPropertyDescriptor: "object/get-own-property-descriptor",
 56       getOwnPropertyDescriptors: "object/get-own-property-descriptors",
 57       getOwnPropertyNames: "object/get-own-property-names",
 58       getOwnPropertySymbols: "object/get-own-property-symbols",
 59       getPrototypeOf: "object/get-prototype-of",
 60       isExtensible: "object/is-extensible",
 61       isFrozen: "object/is-frozen",
 62       isSealed: "object/is-sealed",
 63       is: "object/is",
 64       keys: "object/keys",
 65       preventExtensions: "object/prevent-extensions",
 66       seal: "object/seal",
 67       setPrototypeOf: "object/set-prototype-of",
 68       values: "object/values",
 69     },
 70 
 71     Math: {
 72       acosh: "math/acosh",
 73       asinh: "math/asinh",
 74       atanh: "math/atanh",
 75       cbrt: "math/cbrt",
 76       clz32: "math/clz32",
 77       cosh: "math/cosh",
 78       expm1: "math/expm1",
 79       fround: "math/fround",
 80       hypot: "math/hypot",
 81       imul: "math/imul",
 82       log10: "math/log10",
 83       log1p: "math/log1p",
 84       log2: "math/log2",
 85       sign: "math/sign",
 86       sinh: "math/sinh",
 87       tanh: "math/tanh",
 88       trunc: "math/trunc",
 89       iaddh: "math/iaddh",
 90       isubh: "math/isubh",
 91       imulh: "math/imulh",
 92       umulh: "math/umulh",
 93     },
 94 
 95     Symbol: {
 96       for: "symbol/for",
 97       hasInstance: "symbol/has-instance",
 98       isConcatSpreadable: "symbol/is-concat-spreadable",
 99       iterator: "symbol/iterator",
100       keyFor: "symbol/key-for",
101       match: "symbol/match",
102       replace: "symbol/replace",
103       search: "symbol/search",
104       species: "symbol/species",
105       split: "symbol/split",
106       toPrimitive: "symbol/to-primitive",
107       toStringTag: "symbol/to-string-tag",
108       unscopables: "symbol/unscopables",
109     },
110 
111     String: {
112       at: "string/at",
113       codePointAt: "string/code-point-at",
114       endsWith: "string/ends-with",
115       fromCodePoint: "string/from-code-point",
116       includes: "string/includes",
117       matchAll: "string/match-all",
118       padStart: "string/pad-start",
119       padEnd: "string/pad-end",
120       raw: "string/raw",
121       repeat: "string/repeat",
122       startsWith: "string/starts-with",
123       trim: "string/trim",
124       trimLeft: "string/trim-left",
125       trimRight: "string/trim-right",
126       trimStart: "string/trim-start",
127       trimEnd: "string/trim-end",
128     },
129 
130     Number: {
131       EPSILON: "number/epsilon",
132       isFinite: "number/is-finite",
133       isInteger: "number/is-integer",
134       isNaN: "number/is-nan",
135       isSafeInteger: "number/is-safe-integer",
136       MAX_SAFE_INTEGER: "number/max-safe-integer",
137       MIN_SAFE_INTEGER: "number/min-safe-integer",
138       parseFloat: "number/parse-float",
139       parseInt: "number/parse-int",
140     },
141 
142     Reflect: {
143       apply: "reflect/apply",
144       construct: "reflect/construct",
145       defineProperty: "reflect/define-property",
146       deleteProperty: "reflect/delete-property",
147       getOwnPropertyDescriptor: "reflect/get-own-property-descriptor",
148       getPrototypeOf: "reflect/get-prototype-of",
149       get: "reflect/get",
150       has: "reflect/has",
151       isExtensible: "reflect/is-extensible",
152       ownKeys: "reflect/own-keys",
153       preventExtensions: "reflect/prevent-extensions",
154       setPrototypeOf: "reflect/set-prototype-of",
155       set: "reflect/set",
156       defineMetadata: "reflect/define-metadata",
157       deleteMetadata: "reflect/delete-metadata",
158       getMetadata: "reflect/get-metadata",
159       getMetadataKeys: "reflect/get-metadata-keys",
160       getOwnMetadata: "reflect/get-own-metadata",
161       getOwnMetadataKeys: "reflect/get-own-metadata-keys",
162       hasMetadata: "reflect/has-metadata",
163       hasOwnMetadata: "reflect/has-own-metadata",
164       metadata: "reflect/metadata",
165     },
166 
167     System: {
168       global: "system/global",
169     },
170 
171     Date: {
172       //now: "date/now" // temporary disabled
173     },
174 
175     Function: {
176       // Warning: /virtual/ method - prototype, not static, version
177       //bind: "function/virtual/bind" // temporary disabled
178     },
179   },
180 };

不支持的API需要引入pollify~

参考文章https://shenbao.github.io/ishehui/html/React/Babel%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97.html

转载于:https://www.cnblogs.com/imsomnus/p/9036957.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值