Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-taroapi

Package Overview
Dependencies
Maintainers
1
Versions
778
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-taroapi - npm Package Compare versions

Comparing version 1.3.0-beta.5 to 1.3.0-beta.6

25

dist/index.js

@@ -21,2 +21,3 @@ "use strict";

taroName = node.local.name;
needDefault = true;
}

@@ -55,13 +56,17 @@ else if (t.isImportSpecifier(node)) {

if (apis.has(propertyName)) {
let identifier;
if (invokedApis.has(propertyName)) {
identifier = t.identifier(invokedApis.get(propertyName));
const parentNode = ast.parent;
const isAssignment = t.isAssignmentExpression(parentNode) && parentNode.left === ast.node;
if (!isAssignment) {
let identifier;
if (invokedApis.has(propertyName)) {
identifier = t.identifier(invokedApis.get(propertyName));
}
else {
const newPropertyName = ast.scope.generateUid(propertyName);
invokedApis.set(propertyName, newPropertyName);
/* 未绑定作用域 */
identifier = t.identifier(newPropertyName);
}
ast.replaceWith(identifier);
}
else {
const newPropertyName = ast.scope.generateUid(propertyName);
invokedApis.set(propertyName, newPropertyName);
/* 未绑定作用域 */
identifier = t.identifier(newPropertyName);
}
ast.replaceWith(identifier);
}

@@ -68,0 +73,0 @@ else {

4

package.json
{
"name": "babel-plugin-transform-taroapi",
"version": "1.3.0-beta.5",
"version": "1.3.0-beta.6",
"main": "dist/index.js",

@@ -13,3 +13,3 @@ "license": "MIT",

"devDependencies": {
"@tarojs/taro-h5": "1.3.0-beta.5",
"@tarojs/taro-h5": "1.3.0-beta.6",
"@types/babel-core": "^6.25.5",

@@ -16,0 +16,0 @@ "@types/babel-traverse": "^6.25.4",

@@ -127,1 +127,29 @@ import * as apis from '@tarojs/taro-h5/dist/taroApis'

})
it('should preserve default imports', function () {
const code = `
import Taro from '@tarojs/taro-h5'
console.log(Taro)
`
const result = babel.transform(code, { plugins: [pluginOptions] })
expect(result.code).toMatchSnapshot();
})
it('should preserve assignments in lefthands', function () {
const code = `
import Taro from '@tarojs/taro-h5'
let animation
animation = Taro.createAnimation({
transformOrigin: "50% 50%",
duration: 1000,
timingFunction: "ease",
delay: 0
});
Taro.request()
Taro.request = ''
Taro['request'] = ''
`
const result = babel.transform(code, { plugins: [pluginOptions] })
expect(result.code).toMatchSnapshot();
})

@@ -25,2 +25,3 @@ import { types as Types, PluginObj } from 'babel-core';

taroName = node.local.name
needDefault = true
} else if (t.isImportSpecifier(node)) {

@@ -64,12 +65,17 @@ const propertyName = node.imported.name

if (apis.has(propertyName)) {
let identifier: Types.Identifier
if (invokedApis.has(propertyName)) {
identifier = t.identifier(invokedApis.get(propertyName)!)
} else {
const newPropertyName = ast.scope.generateUid(propertyName)
invokedApis.set(propertyName, newPropertyName)
/* 未绑定作用域 */
identifier = t.identifier(newPropertyName)
const parentNode = ast.parent
const isAssignment = t.isAssignmentExpression(parentNode) && parentNode.left === ast.node
if (!isAssignment) {
let identifier: Types.Identifier
if (invokedApis.has(propertyName)) {
identifier = t.identifier(invokedApis.get(propertyName)!)
} else {
const newPropertyName = ast.scope.generateUid(propertyName)
invokedApis.set(propertyName, newPropertyName)
/* 未绑定作用域 */
identifier = t.identifier(newPropertyName)
}
ast.replaceWith(identifier)
}
ast.replaceWith(identifier)
} else {

@@ -76,0 +82,0 @@ needDefault = true

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc