Socket
Socket
Sign inDemoInstall

@swc/core

Package Overview
Dependencies
Maintainers
1
Versions
696
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swc/core - npm Package Compare versions

Comparing version 1.1.7 to 1.1.8

14

__tests__/transform/api_test.js

@@ -100,1 +100,15 @@ const swc = require("../../");

});
it("should handle nullish coalescing", async () => {
const out = await swc.transform("a ?? 'foo';", {
jsc: {
parser: {
syntax: "ecmascript",
nullishCoalescing: true
}
}
});
expect(out.code).toBe(`a !== null && a !== void 0 ? a : 'foo';
`);
});

2

__tests__/transform/plugin_test.js

@@ -107,3 +107,3 @@ const swc = require("../../");

let v = new Visitor();
return v.visitModule(m);
return v.visitProgram(m);
}

@@ -110,0 +110,0 @@ });

@@ -1,2 +0,2 @@

import { Plugin, ParseOptions, Module, Output, Options } from "./types";
import { Plugin, ParseOptions, Module, Output, Options, Script, Program } from "./types";
export * from "./types";

@@ -11,5 +11,17 @@ /**

constructor();
parse(src: string, options: ParseOptions & {
isModule: false;
}): Promise<Script>;
parse(src: string, options?: ParseOptions): Promise<Module>;
parseSync(src: string, options: ParseOptions & {
isModule: false;
}): Script;
parseSync(src: string, options?: ParseOptions): Module;
parseFile(path: string, options: ParseOptions & {
isModule: false;
}): Promise<Script>;
parseFile(path: string, options?: ParseOptions): Promise<Module>;
parseFileSync(path: string, options: ParseOptions & {
isModule: false;
}): Script;
parseFileSync(path: string, options?: ParseOptions): Module;

@@ -20,3 +32,3 @@ /**

*/
print(m: Module, options?: Options): Promise<Output>;
print(m: Program, options?: Options): Promise<Output>;
/**

@@ -26,18 +38,30 @@ * Note: this method should be invoked on the compiler instance used

*/
printSync(m: Module, options?: Options): Output;
transform(src: string | Module, options?: Options): Promise<Output>;
transformSync(src: string | Module, options?: Options): Output;
printSync(m: Program, options?: Options): Output;
transform(src: string | Program, options?: Options): Promise<Output>;
transformSync(src: string | Program, options?: Options): Output;
transformFile(path: string, options?: Options): Promise<Output>;
transformFileSync(path: string, options?: Options): Output;
}
export declare function parse(src: string, options: ParseOptions & {
isModule: false;
}): Promise<Script>;
export declare function parse(src: string, options?: ParseOptions): Promise<Module>;
export declare function parseSync(src: string, options: ParseOptions & {
isModule: false;
}): Script;
export declare function parseSync(src: string, options?: ParseOptions): Module;
export declare function parseFile(path: string, options: ParseOptions & {
isModule: false;
}): Promise<Script>;
export declare function parseFile(path: string, options?: ParseOptions): Promise<Module>;
export declare function parseFileSync(path: string, options: ParseOptions & {
isModule: false;
}): Script;
export declare function parseFileSync(path: string, options?: ParseOptions): Module;
export declare function print(m: Module, options?: Options): Promise<Output>;
export declare function printSync(m: Module, options?: Options): Output;
export declare function transform(src: string | Module, options?: Options): Promise<Output>;
export declare function transformSync(src: string | Module, options?: Options): Output;
export declare function print(m: Program, options?: Options): Promise<Output>;
export declare function printSync(m: Program, options?: Options): Output;
export declare function transform(src: string | Program, options?: Options): Promise<Output>;
export declare function transformSync(src: string | Program, options?: Options): Output;
export declare function transformFile(path: string, options?: Options): Promise<Output>;
export declare function transformFileSync(path: string, options?: Options): Output;
export declare const DEFAULT_EXTENSIONS: readonly string[];
{
"name": "@swc/core",
"version": "1.1.7",
"version": "1.1.8",
"description": "Super-fast alternative for babel",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -291,2 +291,6 @@ export interface Plugin {

dynamicImport?: boolean;
/**
* Defaults to `false`
*/
nullishCoalescing?: boolean;
}

@@ -478,3 +482,3 @@

export interface MatchPattern {}
export interface MatchPattern { }

@@ -689,6 +693,15 @@ // -------------------------------

| PrivateName
| OptionalChainingExpression
| Invalid;
interface ExpressionBase extends Node, HasSpan {}
interface ExpressionBase extends Node, HasSpan { }
export interface OptionalChainingExpression extends ExpressionBase {
type: "OptionalChainingExpression";
/**
* Call expression or member expression.
*/
expr: Expression
}
export interface ThisExpression extends ExpressionBase {

@@ -1263,3 +1276,4 @@ type: "ThisExpression";

| "in"
| "instanceof";
| "instanceof"
| "??";

@@ -1266,0 +1280,0 @@ export type AssignmentOperator =

@@ -157,3 +157,4 @@ import {

Script,
ExpressionStatement
ExpressionStatement,
OptionalChainingExpression
} from "./types";

@@ -1079,2 +1080,4 @@

return this.visitYieldExpression(n);
case "OptionalChainingExpression":
return this.visitOptionalChainingExpression(n);
case "Invalid":

@@ -1084,2 +1087,6 @@ return n;

}
visitOptionalChainingExpression(n: OptionalChainingExpression): Expression {
n.expr = this.visitExpression(n.expr);
return n
}

@@ -1086,0 +1093,0 @@ visitAssignmentExpression(n: AssignmentExpression): Expression {

export interface Plugin {
(module: Module): Module;
(module: Program): Program;
}
export declare type ParseOptions = ParserConfig & {
comments?: boolean;
script?: boolean;
/**
* Defaults to es3.
*/
target?: JscTarget;
};

@@ -12,2 +17,6 @@ /**

/**
* If true, a file is parsed as a script instead of module.
*/
script?: boolean;
/**
* The working directory that all paths in the programmatic

@@ -168,2 +177,3 @@ * options will be resolved relative to.

plugin?: Plugin;
isModule?: boolean;
}

@@ -183,2 +193,3 @@ export interface CallerOptions {

export interface JscConfig {
loose?: boolean;
/**

@@ -253,2 +264,6 @@ * Defaults to EsParserConfig

dynamicImport?: boolean;
/**
* Defaults to `false`
*/
nullishCoalescing?: boolean;
}

@@ -525,5 +540,12 @@ /**

}
export declare type Expression = ThisExpression | ArrayExpression | ObjectExpression | FunctionExpression | UnaryExpression | UpdateExpression | BinaryExpression | AssignmentExpression | MemberExpression | ConditionalExpression | CallExpression | NewExpression | SequenceExpression | Identifier | Literal | TemplateLiteral | TaggedTemplateExpression | ArrowFunctionExpression | ClassExpression | YieldExpression | MetaProperty | AwaitExpression | ParenthesisExpression | JSXMemberExpression | JSXNamespacedName | JSXEmptyExpression | JSXElement | JSXFragment | TsTypeAssertion | TsNonNullExpression | TsTypeCastExpression | TsAsExpression | PrivateName | Invalid;
export declare type Expression = ThisExpression | ArrayExpression | ObjectExpression | FunctionExpression | UnaryExpression | UpdateExpression | BinaryExpression | AssignmentExpression | MemberExpression | ConditionalExpression | CallExpression | NewExpression | SequenceExpression | Identifier | Literal | TemplateLiteral | TaggedTemplateExpression | ArrowFunctionExpression | ClassExpression | YieldExpression | MetaProperty | AwaitExpression | ParenthesisExpression | JSXMemberExpression | JSXNamespacedName | JSXEmptyExpression | JSXElement | JSXFragment | TsTypeAssertion | TsNonNullExpression | TsTypeCastExpression | TsAsExpression | PrivateName | OptionalChainingExpression | Invalid;
interface ExpressionBase extends Node, HasSpan {
}
export interface OptionalChainingExpression extends ExpressionBase {
type: "OptionalChainingExpression";
/**
* Call expression or member expression.
*/
expr: Expression;
}
export interface ThisExpression extends ExpressionBase {

@@ -762,6 +784,5 @@ type: "ThisExpression";

type: "RegExpLiteral";
pattern: StringLiteral;
flags: RegexFlags;
pattern: string;
flags: string;
}
export declare type RegexFlags = StringLiteral;
export interface NumericLiteral extends Node, HasSpan {

@@ -859,2 +880,3 @@ type: "NumericLiteral";

}
export declare type Program = Module | Script;
export interface Module extends Node, HasSpan, HasInterpreter {

@@ -869,3 +891,3 @@ type: "Module";

export declare type ModuleItem = ModuleDeclaration | Statement;
export declare type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "**" | "|" | "^" | "&" | "||" | "&&" | "in" | "instanceof";
export declare type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "**" | "|" | "^" | "&" | "||" | "&&" | "in" | "instanceof" | "??";
export declare type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=";

@@ -945,3 +967,7 @@ export declare type UpdateOperator = "++" | "--";

}
export declare type Statement = Expression | BlockStatement | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | Declaration;
export interface ExpressionStatement extends Node, HasSpan {
type: "ExpressionStatement";
expression: Expression;
}
export declare type Statement = ExpressionStatement | BlockStatement | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | Declaration;
export interface EmptyStatement extends Node, HasSpan {

@@ -1124,3 +1150,3 @@ type: "EmptyStatement";

}
export declare type TsType = TsKeywordType | TsThisType | TsFnOrConstructorType | TsTypeReference | TsTypeQuery | TsTypeLiteral | TsArrayType | TsTupleType | TsOptionalType | TsRestType | TsUnionOrIntersectionType | TsConditionalType | TsInferType | TsParenthesizedType | TsTypeOperator | TsIndexedAccessType | TsMappedType | TsLiteralType | TsTypePredicate;
export declare type TsType = TsKeywordType | TsThisType | TsFnOrConstructorType | TsTypeReference | TsTypeQuery | TsTypeLiteral | TsArrayType | TsTupleType | TsOptionalType | TsRestType | TsUnionOrIntersectionType | TsConditionalType | TsInferType | TsParenthesizedType | TsTypeOperator | TsIndexedAccessType | TsMappedType | TsLiteralType | TsImportType | TsTypePredicate;
export declare type TsFnOrConstructorType = TsFunctionType | TsConstructorType;

@@ -1158,2 +1184,7 @@ export interface TsKeywordType extends Node, HasSpan {

export declare type TsThisTypeOrIdent = TsThisType | Identifier;
export interface TsImportType extends Node, HasSpan {
argument: StringLiteral;
qualifier?: TsEntityName;
typeParameters?: TsTypeParameterInstantiation;
}
/**

@@ -1164,4 +1195,5 @@ * `typeof` operator

type: "TsTypeQuery";
exprName: TsEntityName;
exprName: TsTypeQueryExpr;
}
export declare type TsTypeQueryExpr = TsEntityName | TsImportType;
export interface TsTypeLiteral extends Node, HasSpan {

@@ -1168,0 +1200,0 @@ type: "TsTypeLiteral";

@@ -1,4 +0,6 @@

import { Module, ModuleItem, ModuleDeclaration, TsNamespaceExportDeclaration, TsExportAssignment, TsImportEqualsDeclaration, ExportAllDeclaration, ExportDefaultExpression, ExportNamedDeclaration, ExportSpecifier, NamedExportSpecifier, ExportNamespaceSpecifer, ExportDefaultSpecifier, StringLiteral, ExportDefaultDeclaration, ExportDeclaration, ArrayExpression, Expression, SpreadElement, ArrowFunctionExpression, BlockStatement, Statement, SwitchStatement, SwitchCase, IfStatement, BreakStatement, WhileStatement, TryStatement, CatchClause, ThrowStatement, ReturnStatement, LabeledStatement, ForStatement, ForOfStatement, ForInStatement, EmptyStatement, DoWhileStatement, DebuggerStatement, WithStatement, Declaration, VariableDeclaration, VariableDeclarator, TsTypeAliasDeclaration, TsModuleDeclaration, TsInterfaceDeclaration, TsEnumDeclaration, FunctionDeclaration, ClassDeclaration, ContinueStatement, TsTypeParameterDeclaration, TsTypeAnnotation, TsType, Pattern, ImportDeclaration, ImportSpecifier, NamedImportSpecifier, ImportNamespaceSpecifier, ImportDefaultSpecifier, Identifier, TsTypeParameterInstantiation, TsExpressionWithTypeArguments, TsEntityName, Decorator, ClassMember, TsIndexSignature, PrivateProperty, PrivateMethod, Constructor, ClassProperty, ClassMethod, Accessibility, PropertyName, NumericLiteral, TsParameterProperty, PrivateName, Fn, TsQualifiedName, TsParameterPropertyParameter, TsModuleReference, TsExternalModuleReference, AssignmentPattern, RestElement, ObjectPattern, ArrayPattern, DefaultDecl, Class, FunctionExpression, ClassExpression, TsFnParameter, TsTypeParameter, ObjectPatternProperty, TsNamespaceBody, TsModuleName, TsNamespaceDeclaration, TsModuleBlock, TsInterfaceBody, TsTypeElement, TsEnumMember, TsEnumMemberId, YieldExpression, UpdateExpression, UnaryExpression, TsTypeCastExpression, TsTypeAssertion, TsNonNullExpression, TsAsExpression, ThisExpression, TemplateLiteral, TaggedTemplateExpression, SequenceExpression, RegExpLiteral, ParenthesisExpression, ObjectExpression, NullLiteral, NewExpression, MetaProperty, MemberExpression, JSXText, JSXNamespacedName, JSXMemberExpression, JSXFragment, JSXEmptyExpression, JSXElement, ConditionalExpression, CallExpression, BooleanLiteral, BinaryExpression, AwaitExpression, KeyValuePatternProperty, AssignmentPatternProperty, Property, AssignmentExpression, Super, JSXObject, JSXClosingFragment, JSXElementChild, JSXOpeningFragment, JSXClosingElement, JSXOpeningElement, JSXAttributeOrSpread, JSXExpressionContainer, JSXSpreadChild, JSXElementName, JSXAttribute, JSXAttributeName, SetterProperty, MethodProperty, KeyValueProperty, GetterProperty, AssignmentProperty, ComputedPropName, Arugment } from "./types";
import { Module, ModuleItem, ModuleDeclaration, TsNamespaceExportDeclaration, TsExportAssignment, TsImportEqualsDeclaration, ExportAllDeclaration, ExportDefaultExpression, ExportNamedDeclaration, ExportSpecifier, NamedExportSpecifier, ExportNamespaceSpecifer, ExportDefaultSpecifier, StringLiteral, ExportDefaultDeclaration, ExportDeclaration, ArrayExpression, Expression, SpreadElement, ArrowFunctionExpression, BlockStatement, Statement, SwitchStatement, SwitchCase, IfStatement, BreakStatement, WhileStatement, TryStatement, CatchClause, ThrowStatement, ReturnStatement, LabeledStatement, ForStatement, ForOfStatement, ForInStatement, EmptyStatement, DoWhileStatement, DebuggerStatement, WithStatement, Declaration, VariableDeclaration, VariableDeclarator, TsTypeAliasDeclaration, TsModuleDeclaration, TsInterfaceDeclaration, TsEnumDeclaration, FunctionDeclaration, ClassDeclaration, ContinueStatement, TsTypeParameterDeclaration, TsTypeAnnotation, TsType, Pattern, ImportDeclaration, ImportSpecifier, NamedImportSpecifier, ImportNamespaceSpecifier, ImportDefaultSpecifier, Identifier, TsTypeParameterInstantiation, TsExpressionWithTypeArguments, TsEntityName, Decorator, ClassMember, TsIndexSignature, PrivateProperty, PrivateMethod, Constructor, ClassProperty, ClassMethod, Accessibility, PropertyName, NumericLiteral, TsParameterProperty, PrivateName, Fn, TsQualifiedName, TsParameterPropertyParameter, TsModuleReference, TsExternalModuleReference, AssignmentPattern, RestElement, ObjectPattern, ArrayPattern, DefaultDecl, Class, FunctionExpression, ClassExpression, TsFnParameter, TsTypeParameter, ObjectPatternProperty, TsNamespaceBody, TsModuleName, TsNamespaceDeclaration, TsModuleBlock, TsInterfaceBody, TsTypeElement, TsEnumMember, TsEnumMemberId, YieldExpression, UpdateExpression, UnaryExpression, TsTypeCastExpression, TsTypeAssertion, TsNonNullExpression, TsAsExpression, ThisExpression, TemplateLiteral, TaggedTemplateExpression, SequenceExpression, RegExpLiteral, ParenthesisExpression, ObjectExpression, NullLiteral, NewExpression, MetaProperty, MemberExpression, JSXText, JSXNamespacedName, JSXMemberExpression, JSXFragment, JSXEmptyExpression, JSXElement, ConditionalExpression, CallExpression, BooleanLiteral, BinaryExpression, AwaitExpression, KeyValuePatternProperty, AssignmentPatternProperty, Property, AssignmentExpression, Super, JSXObject, JSXClosingFragment, JSXElementChild, JSXOpeningFragment, JSXClosingElement, JSXOpeningElement, JSXAttributeOrSpread, JSXExpressionContainer, JSXSpreadChild, JSXElementName, JSXAttribute, JSXAttributeName, SetterProperty, MethodProperty, KeyValueProperty, GetterProperty, AssignmentProperty, ComputedPropName, Arugment, Program, Script, ExpressionStatement, OptionalChainingExpression } from "./types";
export default class Visitor {
visitProgram(n: Program): Program;
visitModule(m: Module): Module;
visitScript(m: Script): Script;
visitModuleItems(items: ModuleItem[]): ModuleItem[];

@@ -103,5 +105,6 @@ visitModuleItem(n: ModuleItem): ModuleItem;

visitDecorator(n: Decorator): Decorator;
visitExpressionStatement(expr: Expression): Statement;
visitExpressionStatement(stmt: ExpressionStatement): Statement;
visitContinueStatement(stmt: ContinueStatement): Statement;
visitExpression(n: Expression): Expression;
visitOptionalChainingExpression(n: OptionalChainingExpression): Expression;
visitAssignmentExpression(n: AssignmentExpression): Expression;

@@ -108,0 +111,0 @@ visitPatternOrExpressison(n: Pattern | Expression): Pattern | Expression;

@@ -6,2 +6,10 @@ "use strict";

}
Visitor.prototype.visitProgram = function (n) {
switch (n.type) {
case "Module":
return this.visitModule(n);
case "Script":
return this.visitScript(n);
}
};
Visitor.prototype.visitModule = function (m) {

@@ -11,2 +19,6 @@ m.body = this.visitModuleItems(m.body);

};
Visitor.prototype.visitScript = function (m) {
m.body = this.visitStatements(m.body);
return m;
};
Visitor.prototype.visitModuleItems = function (items) {

@@ -245,4 +257,6 @@ return items.map(this.visitModuleItem.bind(this));

return this.visitWithStatement(stmt);
case "ExpressionStatement":
return this.visitExpressionStatement(stmt);
default:
return this.visitExpressionStatement(stmt);
throw new Error("Unknown statement type: " + stmt.type);
}

@@ -673,4 +687,5 @@ };

};
Visitor.prototype.visitExpressionStatement = function (expr) {
return this.visitExpression(expr);
Visitor.prototype.visitExpressionStatement = function (stmt) {
stmt.expression = this.visitExpression(stmt.expression);
return stmt;
};

@@ -761,2 +776,4 @@ Visitor.prototype.visitContinueStatement = function (stmt) {

return this.visitYieldExpression(n);
case "OptionalChainingExpression":
return this.visitOptionalChainingExpression(n);
case "Invalid":

@@ -766,2 +783,6 @@ return n;

};
Visitor.prototype.visitOptionalChainingExpression = function (n) {
n.expr = this.visitExpression(n.expr);
return n;
};
Visitor.prototype.visitAssignmentExpression = function (n) {

@@ -832,6 +853,2 @@ n.left = this.visitPatternOrExpressison(n.left);

Visitor.prototype.visitRegExpLiteral = function (n) {
n.pattern = this.visitStringLiteral(n.pattern);
if (n.flags) {
n.flags = this.visitStringLiteral(n.flags);
}
return n;

@@ -838,0 +855,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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