babel-plugin-ng-hot-reload
Advanced tools
Comparing version 2.1.0-alpha001 to 2.1.0-alpha002
@@ -1,2 +0,5 @@ | ||
export default function (babel: any): { | ||
import * as Babel from '@babel/core'; | ||
declare type BabelT = typeof Babel; | ||
declare type PluginOptions = {}; | ||
export default function (babel: BabelT, options?: PluginOptions): { | ||
name: string; | ||
@@ -9,4 +12,6 @@ post(): void; | ||
ImportDeclaration(path: any): void; | ||
ExportNamedDeclaration(path: any): void; | ||
ExportDefaultDeclaration(path: any): void; | ||
}; | ||
}; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function default_1(babel) { | ||
function default_1(babel, options = {}) { | ||
const { types: t } = babel; | ||
@@ -116,7 +116,69 @@ const state = { | ||
}, | ||
ExportNamedDeclaration(path) { | ||
const declaration = path.get('declaration'); | ||
if (declaration.node !== null) { | ||
if (declaration.type === 'VariableDeclaration') { | ||
// Export variable declaration | ||
// e.g: | ||
// export const foo = 'bar', | ||
// bar = 'foo'; | ||
const { declarations } = declaration.node; | ||
declarations.forEach(declaration => { | ||
const identifier = declaration.id; | ||
state.topLevelExports.set(identifier.name, identifier); | ||
}); | ||
} | ||
else { | ||
// Export right before declaration | ||
// e.g: | ||
// export class Foo {}; | ||
const identifier = declaration.get('id').node; | ||
state.topLevelExports.set(identifier.name, identifier); | ||
} | ||
// Replace the export declaration with the actual declaration | ||
path.replaceWith(declaration); | ||
} | ||
else { | ||
// Export specifier | ||
// e.g: | ||
// const foo = 'bar'; | ||
// const bar = 'foo'; | ||
// export { foo, bar as bar2 }; | ||
const { specifiers } = path.node; | ||
if (specifiers && specifiers.length > 0) { | ||
specifiers.forEach(({ local, exported }) => { | ||
state.topLevelExports.set(exported.name, local); | ||
}); | ||
} | ||
// Remove the export | ||
path.remove(); | ||
} | ||
}, | ||
ExportDefaultDeclaration(path) { | ||
const node = path.node; | ||
const name = node.declaration.name; | ||
state.topLevelExports.set('default', path.get('declaration').node); | ||
path.remove(); | ||
const declaration = path.get('declaration'); | ||
if (declaration.type === 'Identifier' || declaration.type === 'MemberExpression') { | ||
// If export is a simple identifier we can use the node directly | ||
// | ||
// Identifier: | ||
// const foo = 'bar'; | ||
// export default foo; | ||
// | ||
// MemberExpression: | ||
// const obj = { | ||
// foo: 'bar' | ||
// }; | ||
// export default obj.foo; | ||
state.topLevelExports.set('default', declaration.node); | ||
// Remove the default export | ||
path.remove(); | ||
} | ||
else { | ||
// If we have a declaration in the default export we have to get the | ||
// identifier through the `id` property | ||
// e.g: | ||
// export default class Foo {} | ||
state.topLevelExports.set('default', declaration.get('id').node); | ||
// Replace the export declaration with the actual declaration | ||
path.replaceWith(declaration); | ||
} | ||
}, | ||
@@ -123,0 +185,0 @@ }, |
{ | ||
"name": "babel-plugin-ng-hot-reload", | ||
"version": "2.1.0-alpha001", | ||
"version": "2.1.0-alpha002", | ||
"main": "dist/index.js", | ||
"author": { | ||
"name": "Felix Haus", | ||
"email": "felixhaus@gmail.com", | ||
"url": "https://felix.house/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ofhouse/babel-plugin-ng-hot-reload.git" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"prepack": "tsc", | ||
"build": "tsc", | ||
"prepack": "cp ../../README.md ../../LICENSE ./ && tsc --p tsconfig.build.json", | ||
"postpack": "rm ./README.md ./LICENSE", | ||
"build": "tsc --p tsconfig.build.json", | ||
"watch": "tsc -w", | ||
"test": "mocha" | ||
"test": "jest" | ||
}, | ||
@@ -19,6 +29,11 @@ "dependencies": { | ||
"devDependencies": { | ||
"@babel/core": "^7.7.4", | ||
"@types/babel__core": "^7.1.3", | ||
"@types/jest": "^24.0.23", | ||
"@types/node": "^12.12.12", | ||
"jest": "^24.9.0", | ||
"jest-snapshot-serializer-raw": "^1.1.0", | ||
"ts-jest": "^24.2.0", | ||
"typescript": "^3.7.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
13344
5
200
1
1
90
0
8