@marko/compiler 5.21.0 → 5.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
2
  var babelTypes = _interopRequireWildcard(require("@babel/types"));
3
- var _builder = _interopRequireDefault(require("@babel/types/lib/builders/builder"));
4
3
  var _utils = _interopRequireDefault(require("@babel/types/lib/definitions/utils"));
4
+ var _validate = _interopRequireDefault(require("@babel/types/lib/validators/validate"));
5
5
  var generatedValidators = _interopRequireWildcard(require("@babel/types/lib/validators/generated"));
6
6
  var referencedValidators = _interopRequireWildcard(require("@babel/types/lib/validators/isReferenced"));
7
7
  var _definitions = _interopRequireWildcard(require("./definitions"));function _getRequireWildcardCache(nodeInterop) {if (typeof WeakMap !== "function") return null;var cacheBabelInterop = new WeakMap();var cacheNodeInterop = new WeakMap();return (_getRequireWildcardCache = function (nodeInterop) {return nodeInterop ? cacheNodeInterop : cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj, nodeInterop) {if (!nodeInterop && obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache(nodeInterop);if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;} /* eslint-disable no-import-assign */
@@ -37,7 +37,7 @@ _definitions.MARKO_TYPES.forEach((typeName) => {
37
37
  babelTypes[checkKey] = (node, opts) => is(typeName, node, opts);
38
38
  babelTypes[assertKey] = (node, opts) => assert(typeName, node, opts);
39
39
  babelTypes[typeName] = babelTypes[lowerName] = function () {
40
- return _builder.default.apply(typeName, arguments);
40
+ return builder(typeName, arguments);
41
41
  };
42
42
  });
43
43
 
@@ -68,4 +68,38 @@ function assert(typeName, node, opts) {
68
68
  }, but instead got "${node.type}".`);
69
69
 
70
70
  }
71
+ }
72
+
73
+ function builder(type, args) {
74
+ const definition = _definitions.default[type];
75
+ const keys = definition.builder;
76
+ const countArgs = args.length;
77
+ if (countArgs > keys.length) {
78
+ throw new Error(
79
+ `${type}: Too many arguments passed. Received ${countArgs} but can receive no more than ${keys.length}`);
80
+
81
+ }
82
+
83
+ const node = { type };
84
+
85
+ for (let i = 0; i < keys.length; ++i) {
86
+ const key = keys[i];
87
+ const field = definition.fields[key];
88
+
89
+ let arg;
90
+ if (i < countArgs) arg = args[i];
91
+ if (arg === undefined) {
92
+ arg = Array.isArray(field.default) ? [] : field.default;
93
+ }
94
+
95
+ node[key] = arg;
96
+ }
97
+
98
+ // (assume all enumerable properties are own)
99
+ // eslint-disable-next-line guard-for-in
100
+ for (const key in node) {
101
+ (0, _validate.default)(node, key, node[key]);
102
+ }
103
+
104
+ return node;
71
105
  }
package/dist/types.d.ts CHANGED
@@ -58,7 +58,7 @@ export interface AssignmentExpression extends BaseNode {
58
58
 
59
59
  export interface BinaryExpression extends BaseNode {
60
60
  type: "BinaryExpression";
61
- operator: "+" | "-" | "/" | "%" | "*" | "**" | "&" | "|" | ">>" | ">>>" | "<<" | "^" | "==" | "===" | "!=" | "!==" | "in" | "instanceof" | ">" | "<" | ">=" | "<=";
61
+ operator: "+" | "-" | "/" | "%" | "*" | "**" | "&" | "|" | ">>" | ">>>" | "<<" | "^" | "==" | "===" | "!=" | "!==" | "in" | "instanceof" | ">" | "<" | ">=" | "<=" | "|>";
62
62
  left: Expression | PrivateName;
63
63
  right: Expression;
64
64
  }
@@ -165,6 +165,7 @@ export interface FunctionDeclaration extends BaseNode {
165
165
  generator: boolean;
166
166
  async: boolean;
167
167
  declare: boolean | null;
168
+ predicate: DeclaredPredicate | InferredPredicate | null;
168
169
  returnType: TypeAnnotation | TSTypeAnnotation | Noop | null;
169
170
  typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop | null;
170
171
  }
@@ -176,6 +177,7 @@ export interface FunctionExpression extends BaseNode {
176
177
  body: BlockStatement;
177
178
  generator: boolean;
178
179
  async: boolean;
180
+ predicate: DeclaredPredicate | InferredPredicate | null;
179
181
  returnType: TypeAnnotation | TSTypeAnnotation | Noop | null;
180
182
  typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop | null;
181
183
  }
@@ -380,7 +382,7 @@ export interface WithStatement extends BaseNode {
380
382
 
381
383
  export interface AssignmentPattern extends BaseNode {
382
384
  type: "AssignmentPattern";
383
- left: Identifier | ObjectPattern | ArrayPattern | MemberExpression;
385
+ left: Identifier | ObjectPattern | ArrayPattern | MemberExpression | TSAsExpression | TSTypeAssertion | TSNonNullExpression;
384
386
  right: Expression;
385
387
  decorators: Array<Decorator> | null;
386
388
  typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop | null;
@@ -401,6 +403,7 @@ export interface ArrowFunctionExpression extends BaseNode {
401
403
  async: boolean;
402
404
  expression: boolean;
403
405
  generator: boolean;
406
+ predicate: DeclaredPredicate | InferredPredicate | null;
404
407
  returnType: TypeAnnotation | TSTypeAnnotation | Noop | null;
405
408
  typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop | null;
406
409
  }
@@ -866,9 +869,9 @@ export interface NumberTypeAnnotation extends BaseNode {
866
869
  export interface ObjectTypeAnnotation extends BaseNode {
867
870
  type: "ObjectTypeAnnotation";
868
871
  properties: Array<ObjectTypeProperty | ObjectTypeSpreadProperty>;
869
- indexers: Array<ObjectTypeIndexer> | null;
870
- callProperties: Array<ObjectTypeCallProperty> | null;
871
- internalSlots: Array<ObjectTypeInternalSlot> | null;
872
+ indexers: Array<ObjectTypeIndexer>;
873
+ callProperties: Array<ObjectTypeCallProperty>;
874
+ internalSlots: Array<ObjectTypeInternalSlot>;
872
875
  exact: boolean;
873
876
  inexact: boolean | null;
874
877
  }
@@ -1743,8 +1746,8 @@ export type Function = FunctionDeclaration | FunctionExpression | ObjectMethod |
1743
1746
  export type FunctionParent = FunctionDeclaration | FunctionExpression | ObjectMethod | ArrowFunctionExpression | ClassMethod | ClassPrivateMethod | StaticBlock;
1744
1747
  export type Pureish = FunctionDeclaration | FunctionExpression | StringLiteral | NumericLiteral | NullLiteral | BooleanLiteral | RegExpLiteral | ArrowFunctionExpression | BigIntLiteral | DecimalLiteral;
1745
1748
  export type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration | ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration | DeclareClass | DeclareFunction | DeclareInterface | DeclareModule | DeclareModuleExports | DeclareTypeAlias | DeclareOpaqueType | DeclareVariable | DeclareExportDeclaration | DeclareExportAllDeclaration | InterfaceDeclaration | OpaqueType | TypeAlias | EnumDeclaration | TSDeclareFunction | TSInterfaceDeclaration | TSTypeAliasDeclaration | TSEnumDeclaration | TSModuleDeclaration;
1746
- export type PatternLike = Identifier | RestElement | AssignmentPattern | ArrayPattern | ObjectPattern;
1747
- export type LVal = Identifier | MemberExpression | RestElement | AssignmentPattern | ArrayPattern | ObjectPattern | TSParameterProperty;
1749
+ export type PatternLike = Identifier | RestElement | AssignmentPattern | ArrayPattern | ObjectPattern | TSAsExpression | TSTypeAssertion | TSNonNullExpression;
1750
+ export type LVal = Identifier | MemberExpression | RestElement | AssignmentPattern | ArrayPattern | ObjectPattern | TSParameterProperty | TSAsExpression | TSTypeAssertion | TSNonNullExpression;
1748
1751
  export type TSEntityName = Identifier | TSQualifiedName;
1749
1752
  export type Literal = StringLiteral | NumericLiteral | NullLiteral | BooleanLiteral | RegExpLiteral | TemplateLiteral | BigIntLiteral | DecimalLiteral;
1750
1753
  export type Immutable = StringLiteral | NumericLiteral | NullLiteral | BooleanLiteral | BigIntLiteral | JSXAttribute | JSXClosingElement | JSXElement | JSXExpressionContainer | JSXSpreadChild | JSXOpeningElement | JSXText | JSXFragment | JSXOpeningFragment | JSXClosingFragment | DecimalLiteral;
@@ -1832,7 +1835,7 @@ export interface Aliases {
1832
1835
 
1833
1836
  export function arrayExpression(elements?: Array<null | Expression | SpreadElement>): ArrayExpression;
1834
1837
  export function assignmentExpression(operator: string, left: LVal, right: Expression): AssignmentExpression;
1835
- export function binaryExpression(operator: "+" | "-" | "/" | "%" | "*" | "**" | "&" | "|" | ">>" | ">>>" | "<<" | "^" | "==" | "===" | "!=" | "!==" | "in" | "instanceof" | ">" | "<" | ">=" | "<=", left: Expression | PrivateName, right: Expression): BinaryExpression;
1838
+ export function binaryExpression(operator: "+" | "-" | "/" | "%" | "*" | "**" | "&" | "|" | ">>" | ">>>" | "<<" | "^" | "==" | "===" | "!=" | "!==" | "in" | "instanceof" | ">" | "<" | ">=" | "<=" | "|>", left: Expression | PrivateName, right: Expression): BinaryExpression;
1836
1839
  export function interpreterDirective(value: string): InterpreterDirective;
1837
1840
  export function directive(value: DirectiveLiteral): Directive;
1838
1841
  export function directiveLiteral(value: string): DirectiveLiteral;
@@ -1881,7 +1884,7 @@ export function variableDeclaration(kind: "var" | "let" | "const", declarations:
1881
1884
  export function variableDeclarator(id: LVal, init?: Expression | null): VariableDeclarator;
1882
1885
  export function whileStatement(test: Expression, body: Statement): WhileStatement;
1883
1886
  export function withStatement(object: Expression, body: Statement): WithStatement;
1884
- export function assignmentPattern(left: Identifier | ObjectPattern | ArrayPattern | MemberExpression, right: Expression): AssignmentPattern;
1887
+ export function assignmentPattern(left: Identifier | ObjectPattern | ArrayPattern | MemberExpression | TSAsExpression | TSTypeAssertion | TSNonNullExpression, right: Expression): AssignmentPattern;
1885
1888
  export function arrayPattern(elements: Array<null | PatternLike>): ArrayPattern;
1886
1889
  export function arrowFunctionExpression(params: Array<Identifier | Pattern | RestElement>, body: BlockStatement | Expression, async?: boolean): ArrowFunctionExpression;
1887
1890
  export function classBody(body: Array<ClassMethod | ClassPrivateMethod | ClassProperty | ClassPrivateProperty | ClassAccessorProperty | TSDeclareMethod | TSIndexSignature | StaticBlock>): ClassBody;
@@ -1950,7 +1953,7 @@ export function emptyTypeAnnotation(): EmptyTypeAnnotation;
1950
1953
  export function nullableTypeAnnotation(typeAnnotation: FlowType): NullableTypeAnnotation;
1951
1954
  export function numberLiteralTypeAnnotation(value: number): NumberLiteralTypeAnnotation;
1952
1955
  export function numberTypeAnnotation(): NumberTypeAnnotation;
1953
- export function objectTypeAnnotation(properties: Array<ObjectTypeProperty | ObjectTypeSpreadProperty>, indexers?: Array<ObjectTypeIndexer> | null, callProperties?: Array<ObjectTypeCallProperty> | null, internalSlots?: Array<ObjectTypeInternalSlot> | null, exact?: boolean): ObjectTypeAnnotation;
1956
+ export function objectTypeAnnotation(properties: Array<ObjectTypeProperty | ObjectTypeSpreadProperty>, indexers?: Array<ObjectTypeIndexer>, callProperties?: Array<ObjectTypeCallProperty>, internalSlots?: Array<ObjectTypeInternalSlot>, exact?: boolean): ObjectTypeAnnotation;
1954
1957
  export function objectTypeInternalSlot(id: Identifier, value: FlowType, optional: boolean, _static: boolean, method: boolean): ObjectTypeInternalSlot;
1955
1958
  export function objectTypeCallProperty(value: FlowType): ObjectTypeCallProperty;
1956
1959
  export function objectTypeIndexer(id: Identifier | null | undefined, key: FlowType, value: FlowType, variance?: Variance | null): ObjectTypeIndexer;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/compiler",
3
3
  "description": "Marko template to JS compiler.",
4
- "version": "5.21.0",
4
+ "version": "5.21.3",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md",
7
7
  "dependencies": {
@@ -13,10 +13,10 @@
13
13
  "@babel/runtime": "^7.16.0",
14
14
  "@babel/traverse": "^7.16.0",
15
15
  "@babel/types": "^7.16.0",
16
- "@marko/babel-utils": "^5.21.0",
16
+ "@marko/babel-utils": "^5.21.1",
17
17
  "complain": "^1.6.0",
18
18
  "he": "^1.2.0",
19
- "htmljs-parser": "^3.3.1",
19
+ "htmljs-parser": "^3.3.4",
20
20
  "jsesc": "^3.0.2",
21
21
  "lasso-package-root": "^1.0.1",
22
22
  "property-handlers": "^1.1.1",
@@ -28,7 +28,7 @@
28
28
  "strip-json-comments": "^3.1.1"
29
29
  },
30
30
  "devDependencies": {
31
- "@marko/translator-default": "^5.21.0"
31
+ "@marko/translator-default": "^5.21.1"
32
32
  },
33
33
  "files": [
34
34
  "dist",
@@ -48,7 +48,7 @@
48
48
  "plugin"
49
49
  ],
50
50
  "license": "MIT",
51
- "main": "src/index.js",
51
+ "main": "dist/index.js",
52
52
  "main:dev": "src/index.js",
53
53
  "main:npm": "dist/index.js",
54
54
  "publishConfig": {
package/src/index.js DELETED
@@ -1,117 +0,0 @@
1
- export * as types from "./babel-types";
2
- import path from "path";
3
- import * as babel from "@babel/core";
4
- import corePlugin from "./babel-plugin";
5
- import defaultConfig from "./config";
6
- import * as taglib from "./taglib";
7
- import shouldOptimize from "./util/should-optimize";
8
- import tryLoadTranslator from "./util/try-load-translator";
9
- export { taglib };
10
-
11
- let globalConfig = { ...defaultConfig };
12
- export function configure(newConfig) {
13
- globalConfig = { ...defaultConfig, ...newConfig };
14
- }
15
-
16
- export async function compile(src, filename, config) {
17
- const babelConfig = loadBabelConfig(filename, config);
18
- const babelResult = await babel.transformAsync(src, babelConfig);
19
- scheduleDefaultClear(config);
20
- return buildResult(babelResult);
21
- }
22
-
23
- export function compileSync(src, filename, config) {
24
- const babelConfig = loadBabelConfig(filename, config);
25
- const babelResult = babel.transformSync(src, babelConfig);
26
- scheduleDefaultClear(config);
27
- return buildResult(babelResult);
28
- }
29
-
30
- export async function compileFile(filename, config) {
31
- return new Promise((resolve, reject) => {
32
- getFs(config).readFile(filename, "utf-8", (err, src) => {
33
- if (err) {
34
- return reject(err);
35
- }
36
-
37
- return resolve(compile(src, filename, config));
38
- });
39
- });
40
- }
41
-
42
- export function compileFileSync(filename, config) {
43
- const src = getFs(config).readFileSync(filename, "utf-8");
44
- return compileSync(src, filename, config);
45
- }
46
-
47
- export function getRuntimeEntryFiles(output, requestedTranslator) {
48
- const translator = tryLoadTranslator(requestedTranslator);
49
- if (translator && translator.getRuntimeEntryFiles) {
50
- return translator.getRuntimeEntryFiles(output, shouldOptimize());
51
- }
52
-
53
- return [];
54
- }
55
-
56
- function loadBabelConfig(filename, config) {
57
- const markoConfig = { ...globalConfig, ...config, babelConfig: undefined };
58
- const requiredPlugins = [[corePlugin, markoConfig]];
59
- const baseBabelConfig = {
60
- filenameRelative: filename
61
- ? path.relative(process.cwd(), filename)
62
- : undefined,
63
- sourceFileName: filename ? path.basename(filename) : undefined,
64
- ...(config && config.babelConfig),
65
- filename,
66
- sourceType: "module",
67
- sourceMaps: markoConfig.sourceMaps,
68
- code: markoConfig.code,
69
- ast: markoConfig.ast
70
- };
71
-
72
- if (markoConfig.modules === "cjs") {
73
- requiredPlugins.push([
74
- require.resolve("@babel/plugin-transform-modules-commonjs"),
75
- { loose: true }
76
- ]);
77
- }
78
-
79
- baseBabelConfig.plugins = requiredPlugins.concat(
80
- baseBabelConfig.plugins || []
81
- );
82
-
83
- return babel.loadPartialConfig(baseBabelConfig).options;
84
- }
85
-
86
- function buildResult(babelResult) {
87
- const {
88
- ast,
89
- map,
90
- code,
91
- metadata: { marko: meta }
92
- } = babelResult;
93
- return { ast, map, code, meta };
94
- }
95
-
96
- let clearingDefaultCache = false;
97
- function scheduleDefaultClear(config) {
98
- if (
99
- !clearingDefaultCache &&
100
- (clearingDefaultCache = isDefaultCache(config))
101
- ) {
102
- setImmediate(_clearDefaults);
103
- }
104
- }
105
-
106
- export function _clearDefaults() {
107
- clearingDefaultCache = false;
108
- globalConfig.cache.clear();
109
- }
110
-
111
- function isDefaultCache(config) {
112
- return !config.cache || config.cache === globalConfig.cache;
113
- }
114
-
115
- function getFs(config) {
116
- return config.fileSystem || globalConfig.fileSystem;
117
- }