Skip to content

Commit

Permalink
fix: Fix bindings (swc-project#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Sep 26, 2022
1 parent b1bf39d commit e8c28cd
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 14 deletions.
1 change: 1 addition & 0 deletions crates/html_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn minify_inner(code: &str, opts: MinifyOptions) -> anyhow::Result<String> {
let mut gen = CodeGenerator::new(
&mut wr,
CodegenConfig {
minify: true,
..Default::default()
},
);
Expand Down
56 changes: 53 additions & 3 deletions packages/css/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,63 @@
"use strict";
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (
!desc ||
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
) {
desc = {
enumerable: true,
get: function () {
return m[k];
},
};
}
Object.defineProperty(o, k2, desc);
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __setModuleDefault =
(this && this.__setModuleDefault) ||
(Object.create
? function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}
: function (o, v) {
o["default"] = v;
});
var __importStar =
(this && this.__importStar) ||
function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.minifySync = exports.minify = void 0;
const binding = require("./binding");
const binding = __importStar(require("./binding"));
async function minify(content, options) {
return binding.minify(content, toBuffer(options));
return binding.minify(
content,
toBuffer(options !== null && options !== void 0 ? options : {})
);
}
exports.minify = minify;
function minifySync(content, options) {
return binding.minifySync(content, toBuffer(options));
return binding.minifySync(
content,
toBuffer(options !== null && options !== void 0 ? options : {})
);
}
exports.minifySync = minifySync;
function toBuffer(t) {
Expand Down
6 changes: 3 additions & 3 deletions packages/css/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import binding = require("./binding");
import * as binding from "./binding";

export async function minify(
content: Buffer,
options: any
): Promise<binding.TransformOutput> {
return binding.minify(content, toBuffer(options));
return binding.minify(content, toBuffer(options ?? {}));
}

export function minifySync(content: Buffer, options: any) {
return binding.minifySync(content, toBuffer(options));
return binding.minifySync(content, toBuffer(options ?? {}));
}

function toBuffer(t: any): Buffer {
Expand Down
56 changes: 53 additions & 3 deletions packages/html/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,63 @@
"use strict";
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (
!desc ||
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
) {
desc = {
enumerable: true,
get: function () {
return m[k];
},
};
}
Object.defineProperty(o, k2, desc);
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __setModuleDefault =
(this && this.__setModuleDefault) ||
(Object.create
? function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}
: function (o, v) {
o["default"] = v;
});
var __importStar =
(this && this.__importStar) ||
function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.minifySync = exports.minify = void 0;
const binding = require("./binding");
const binding = __importStar(require("./binding"));
async function minify(content, options) {
return binding.minify(content, toBuffer(options));
return binding.minify(
content,
toBuffer(options !== null && options !== void 0 ? options : {})
);
}
exports.minify = minify;
function minifySync(content, options) {
return binding.minifySync(content, toBuffer(options));
return binding.minifySync(
content,
toBuffer(options !== null && options !== void 0 ? options : {})
);
}
exports.minifySync = minifySync;
function toBuffer(t) {
Expand Down
10 changes: 5 additions & 5 deletions packages/html/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import binding = require("./binding");
import * as binding from "./binding";

export async function minify(content: Buffer, options: any): Promise<string> {
return binding.minify(content, toBuffer(options));
export async function minify(content: Buffer, options?: any): Promise<string> {
return binding.minify(content, toBuffer(options ?? {}));
}

export function minifySync(content: Buffer, options: any) {
return binding.minifySync(content, toBuffer(options));
export function minifySync(content: Buffer, options?: any) {
return binding.minifySync(content, toBuffer(options ?? {}));
}

function toBuffer(t: any): Buffer {
Expand Down

0 comments on commit e8c28cd

Please sign in to comment.