Skip to content

Commit

Permalink
Always use the last plugin version
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 7, 2018
1 parent 9953836 commit e70d0f0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/babel-plugin-class-features/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ import {
isLoose,
} from "./features";

import pkg from "../package.json";

export { enableFeature, FEATURES, setLoose };

// Note: Versions are represented as an integer. e.g. 7.1.5 is represented
// as 70000100005. This method is easier than using a semver-parsing
// package, but it breaks if we relese x.y.z where x, y or z are
// greater than 99_999.
const version = pkg.version.split(".").reduce((v, x) => v * 1e5 + +x, 0);
const versionKey = "@babel/plugin-class-features/version";

const getFeatureOptions = (options, name) => {
const value = options[name];

Expand Down Expand Up @@ -56,6 +65,10 @@ export default declare((api, options) => {
},

pre() {
if (!this.file.get(versionKey) || this.file.get(versionKey) < version) {
this.file.set(versionKey, version);
}

if (fields.enabled) {
enableFeature(this.file, FEATURES.fields, fields.loose);
}
Expand All @@ -71,6 +84,8 @@ export default declare((api, options) => {

visitor: {
Class(path, state) {
if (this.file.get(versionKey) !== version) return;

verifyUsedFeatures(path, this.file);

// Only fields are currently supported, this needs to be moved somewhere
Expand Down

0 comments on commit e70d0f0

Please sign in to comment.