mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
feat: update apis/tests for new compiler
BREAKING CHANGE: api for compile-time tags has changed. This affects tranformer/node-factory/code-generator tags. Co-authored-by: Michael Rawlings <mirawlings@ebay.com> Co-authored-by: Dylan Piercey <dpiercey@ebay.com> Co-authored-by: Andrew Gliga <agliga@ebay.com>
This commit is contained in:
parent
c1630543fb
commit
ea6736d085
@ -5,40 +5,23 @@
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var nodePath = require("path");
|
var nodePath = require("path");
|
||||||
var cwd = process.cwd();
|
var cwd = process.cwd();
|
||||||
var resolveFrom = require("resolve-from");
|
var resolveFrom = require("resolve-from").silent;
|
||||||
|
|
||||||
// Try to use the Marko compiler installed with the project
|
// Try to use the Marko compiler installed with the project
|
||||||
var markoCompilerPath;
|
var markoCompilerPath = resolveFrom(process.cwd(), "marko/compiler");
|
||||||
const markocPkgVersion = require("../package.json").version;
|
const markocPkgVersion = require("../package.json").version;
|
||||||
|
|
||||||
var markoPkgVersion;
|
var markoPkgPath = resolveFrom(process.cwd(), "marko/package.json");
|
||||||
try {
|
var markoPkgVersion = markoPkgPath && require(markoPkgPath).version;
|
||||||
var markoPkgPath = resolveFrom(process.cwd(), "marko/package.json");
|
|
||||||
markoPkgVersion = require(markoPkgPath).version;
|
|
||||||
} catch (e) {
|
|
||||||
/* ignore error */
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
var markoCompiler = markoCompilerPath
|
||||||
markoCompilerPath = resolveFrom(process.cwd(), "marko/compiler");
|
? require(markoCompilerPath)
|
||||||
} catch (e) {
|
: require("../compiler");
|
||||||
/* ignore error */
|
|
||||||
}
|
|
||||||
|
|
||||||
var markoCompiler;
|
|
||||||
|
|
||||||
if (markoCompilerPath) {
|
|
||||||
markoCompiler = require(markoCompilerPath);
|
|
||||||
} else {
|
|
||||||
markoCompiler = require("../compiler");
|
|
||||||
}
|
|
||||||
|
|
||||||
var Minimatch = require("minimatch").Minimatch;
|
var Minimatch = require("minimatch").Minimatch;
|
||||||
|
|
||||||
var appModulePath = require("app-module-path");
|
var appModulePath = require("app-module-path");
|
||||||
|
|
||||||
markoCompiler.defaultOptions.checkUpToDate = false;
|
|
||||||
|
|
||||||
var mmOptions = {
|
var mmOptions = {
|
||||||
matchBase: true,
|
matchBase: true,
|
||||||
dot: true,
|
dot: true,
|
||||||
@ -84,7 +67,16 @@ var args = require("argly")
|
|||||||
},
|
},
|
||||||
"--vdom -V": {
|
"--vdom -V": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
description: "VDOM output"
|
description: "VDOM output (deprecated, prefer --browser)"
|
||||||
|
},
|
||||||
|
"--browser -b": {
|
||||||
|
type: "boolean",
|
||||||
|
description: "Browser output"
|
||||||
|
},
|
||||||
|
"--source-maps -s": {
|
||||||
|
type: "string",
|
||||||
|
description:
|
||||||
|
"Output a sourcemap beside the compiled file. (use --source-maps inline for an inline source map)"
|
||||||
},
|
},
|
||||||
"--version -v": {
|
"--version -v": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
@ -132,7 +124,7 @@ var output = "html";
|
|||||||
|
|
||||||
var isForBrowser = false;
|
var isForBrowser = false;
|
||||||
|
|
||||||
if (args.vdom) {
|
if (args.vdom || args.browser) {
|
||||||
output = "vdom";
|
output = "vdom";
|
||||||
isForBrowser = true;
|
isForBrowser = true;
|
||||||
}
|
}
|
||||||
@ -140,6 +132,8 @@ if (args.vdom) {
|
|||||||
var compileOptions = {
|
var compileOptions = {
|
||||||
output: output,
|
output: output,
|
||||||
browser: isForBrowser,
|
browser: isForBrowser,
|
||||||
|
sourceOnly: false,
|
||||||
|
sourceMaps: args.sourceMaps || false,
|
||||||
compilerType: "markoc",
|
compilerType: "markoc",
|
||||||
compilerVersion: markoPkgVersion || markocPkgVersion
|
compilerVersion: markoPkgVersion || markocPkgVersion
|
||||||
};
|
};
|
||||||
@ -348,7 +342,7 @@ if (args.clean) {
|
|||||||
|
|
||||||
context.beginAsync();
|
context.beginAsync();
|
||||||
|
|
||||||
markoCompiler.compileFile(path, compileOptions, function(err, src) {
|
markoCompiler.compileFile(path, compileOptions, function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
failed.push(
|
failed.push(
|
||||||
'Failed to compile "' +
|
'Failed to compile "' +
|
||||||
@ -360,8 +354,9 @@ if (args.clean) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var src = result.code;
|
||||||
context.beginAsync();
|
context.beginAsync();
|
||||||
fs.writeFile(outPath, src, { encoding: "utf8" }, function(err) {
|
fs.writeFile(outPath, src, "utf8", function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
failed.push(
|
failed.push(
|
||||||
'Failed to write "' + path + '". Error: ' + (err.stack || err)
|
'Failed to write "' + path + '". Error: ' + (err.stack || err)
|
||||||
@ -370,6 +365,31 @@ if (args.clean) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.map) {
|
||||||
|
fs.writeFile(
|
||||||
|
outPath + ".map",
|
||||||
|
JSON.stringify(result.map),
|
||||||
|
"utf-8",
|
||||||
|
function(err) {
|
||||||
|
if (err) {
|
||||||
|
failed.push(
|
||||||
|
'Failed to write sourcemap"' +
|
||||||
|
path +
|
||||||
|
'". Error: ' +
|
||||||
|
(err.stack || err)
|
||||||
|
);
|
||||||
|
context.endAsync(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
compileCount++;
|
||||||
|
context.endAsync();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
compileCount++;
|
compileCount++;
|
||||||
context.endAsync();
|
context.endAsync();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,50 +1,35 @@
|
|||||||
{
|
{
|
||||||
"name": "marko",
|
"name": "marko",
|
||||||
"version": "4.18.48",
|
"version": "5.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
|
"description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"app-module-path": "^2.2.0",
|
"app-module-path": "^2.2.0",
|
||||||
"argly": "^1.0.0",
|
"argly": "^1.0.0",
|
||||||
"browser-refresh-client": "^1.0.0",
|
|
||||||
"camelcase": "^5.0.0",
|
|
||||||
"char-props": "~0.1.5",
|
|
||||||
"complain": "^1.6.0",
|
"complain": "^1.6.0",
|
||||||
"deresolve": "^1.1.2",
|
"deresolve": "^1.1.2",
|
||||||
"escodegen": "^1.8.1",
|
|
||||||
"esprima": "^4.0.0",
|
|
||||||
"estraverse": "^4.3.0",
|
|
||||||
"events-light": "^1.0.0",
|
"events-light": "^1.0.0",
|
||||||
"he": "^1.1.0",
|
|
||||||
"htmljs-parser": "^2.7.1",
|
"htmljs-parser": "^2.7.1",
|
||||||
"lasso-caching-fs": "^1.0.1",
|
"lasso-caching-fs": "^1.0.1",
|
||||||
"lasso-modules-client": "^2.0.4",
|
|
||||||
"lasso-package-root": "^1.0.1",
|
"lasso-package-root": "^1.0.1",
|
||||||
"listener-tracker": "^2.0.0",
|
"listener-tracker": "^2.0.0",
|
||||||
"minimatch": "^3.0.2",
|
"minimatch": "^3.0.2",
|
||||||
"property-handlers": "^1.0.0",
|
"property-handlers": "^1.0.0",
|
||||||
"raptor-regexp": "^1.0.0",
|
"raptor-regexp": "^1.0.0",
|
||||||
"raptor-util": "^3.2.0",
|
"raptor-util": "^3.2.0",
|
||||||
"resolve-from": "^2.0.0",
|
"resolve-from": "^5.0.0",
|
||||||
"self-closing-tags": "^1.0.1",
|
"self-closing-tags": "^1.0.1",
|
||||||
"simple-sha1": "^2.1.0",
|
|
||||||
"strip-json-comments": "^2.0.1",
|
"strip-json-comments": "^2.0.1",
|
||||||
"warp10": "^2.0.1"
|
"warp10": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@marko/migrate": "^5.1.0",
|
"@marko/compiler": "^5.0.0",
|
||||||
"bluebird": "^3.4.7",
|
"bluebird": "^3.4.7",
|
||||||
"caller-path": "^2.0.0",
|
"chai": "^4.2.0",
|
||||||
"chai": "^3.3.0",
|
|
||||||
"diffable-html": "^2.1.0",
|
"diffable-html": "^2.1.0",
|
||||||
"express": "^4.16.1",
|
"express": "^4.16.1",
|
||||||
"it-fails": "^1.0.0",
|
"it-fails": "^1.0.4",
|
||||||
"jquery": "^3.1.1",
|
|
||||||
"jsdom-context-require": "^1.0.1",
|
"jsdom-context-require": "^1.0.1",
|
||||||
"lasso-resolve-from": "^1.2.0",
|
|
||||||
"marko-widgets": "^7.0.1",
|
|
||||||
"micromatch": "^3.0.4",
|
|
||||||
"request": "^2.72.0",
|
|
||||||
"through": "^2.3.4",
|
"through": "^2.3.4",
|
||||||
"through2": "^2.0.1"
|
"through2": "^2.0.1"
|
||||||
},
|
},
|
||||||
@ -52,8 +37,7 @@
|
|||||||
"browser": {
|
"browser": {
|
||||||
"./compiler.js": "./compiler-browser.marko",
|
"./compiler.js": "./compiler-browser.marko",
|
||||||
"./components.js": "./components-browser.marko",
|
"./components.js": "./components-browser.marko",
|
||||||
"./index.js": "./index-browser.marko",
|
"./index.js": "./index-browser.marko"
|
||||||
"./legacy-components.js": "./legacy-components-browser.marko"
|
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"markoc": "bin/markoc"
|
"markoc": "bin/markoc"
|
||||||
@ -66,9 +50,6 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/marko-js/marko.git"
|
"url": "https://github.com/marko-js/marko.git"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
|
||||||
"registry": "https://registry.npmjs.org/"
|
|
||||||
},
|
|
||||||
"author": "Patrick Steele-Idem <pnidem@gmail.com>",
|
"author": "Patrick Steele-Idem <pnidem@gmail.com>",
|
||||||
"maintainers": [
|
"maintainers": [
|
||||||
"Patrick Steele-Idem <pnidem@gmail.com>",
|
"Patrick Steele-Idem <pnidem@gmail.com>",
|
||||||
@ -96,22 +77,14 @@
|
|||||||
"bin",
|
"bin",
|
||||||
"dist",
|
"dist",
|
||||||
"docs",
|
"docs",
|
||||||
"helpers",
|
|
||||||
"src",
|
"src",
|
||||||
"browser-refresh.js",
|
|
||||||
"compiler-browser.marko",
|
"compiler-browser.marko",
|
||||||
"compiler.js",
|
"compiler.js",
|
||||||
"components-browser.marko",
|
"components-browser.marko",
|
||||||
"components.js",
|
"components.js",
|
||||||
"env.js",
|
"env.js",
|
||||||
"express.js",
|
|
||||||
"hot-reload.js",
|
|
||||||
"index-browser.marko",
|
"index-browser.marko",
|
||||||
"index.js",
|
"index.js",
|
||||||
"jquery.marko",
|
"node-require.js"
|
||||||
"legacy-components-browser.marko",
|
|
||||||
"legacy-components.js",
|
|
||||||
"node-require.js",
|
|
||||||
"ready.marko"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,52 +1,11 @@
|
|||||||
var config;
|
var config;
|
||||||
|
|
||||||
/* globals window */
|
|
||||||
var g = typeof window === "undefined" ? global : window;
|
var g = typeof window === "undefined" ? global : window;
|
||||||
|
|
||||||
function shouldAssumeUpToDate() {
|
|
||||||
if (process.env.MARKO_CLEAN != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.MARKO_ASSUME_UP_TO_DATE != null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g.__MARKO_CONFIG) {
|
if (g.__MARKO_CONFIG) {
|
||||||
config = g.__MARKO_CONFIG;
|
config = g.__MARKO_CONFIG;
|
||||||
} else {
|
} else {
|
||||||
config = g.__MARKO_CONFIG = {
|
config = g.__MARKO_CONFIG = {
|
||||||
/**
|
|
||||||
* If true, then the compiler will check the disk to see if a previously compiled
|
|
||||||
* template is the same age or newer than the source template. If so, the previously
|
|
||||||
* compiled template will be loaded. Otherwise, the template will be recompiled
|
|
||||||
* and saved to disk.
|
|
||||||
*
|
|
||||||
* If false, the template will always be recompiled. If `writeToDisk` is false
|
|
||||||
* then this option will be ignored.
|
|
||||||
*/
|
|
||||||
checkUpToDate: process.env.MARKO_CLEAN ? false : true,
|
|
||||||
/**
|
|
||||||
* If true (the default) then compiled templates will be written to disk. If false,
|
|
||||||
* compiled templates will not be written to disk (i.e., no `.marko.js` file will
|
|
||||||
* be generated)
|
|
||||||
*/
|
|
||||||
writeToDisk: true,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If true, then the compiled template on disk will assumed to be up-to-date if it exists.
|
|
||||||
*/
|
|
||||||
assumeUpToDate: shouldAssumeUpToDate(),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If true, whitespace will be preserved in templates. Defaults to false.
|
|
||||||
* @type {Boolean}
|
|
||||||
*/
|
|
||||||
preserveWhitespace: false,
|
|
||||||
|
|
||||||
// The default output mode for compiled templates
|
// The default output mode for compiled templates
|
||||||
output: "html",
|
output: "html",
|
||||||
|
|
||||||
@ -63,10 +22,19 @@ if (g.__MARKO_CONFIG) {
|
|||||||
ignoreUnrecognizedTags: false,
|
ignoreUnrecognizedTags: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls whether or not a key should be assigned to all HTML
|
* Whether source maps should be output with the compiled templates.
|
||||||
* and custom tags at compile-time. The default is `true`
|
* When `true` a `map` property will be available on the compile result.
|
||||||
|
* When `"inline"` the sourcemap will be inlined as a comment in the output code.
|
||||||
|
* When `"both"` both of the above will be used.
|
||||||
*/
|
*/
|
||||||
autoKeyEnabled: true
|
sourceMaps: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This option inlines all of the meta data in the template.
|
||||||
|
* You can also access this metadata via `compile(...).meta`.
|
||||||
|
* This API is sticking around for compatibility purposes.
|
||||||
|
*/
|
||||||
|
meta: true
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.env.MARKO_CONFIG) {
|
if (process.env.MARKO_CONFIG) {
|
||||||
|
|||||||
@ -1,36 +1,26 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Compiler = require("./Compiler");
|
var compiler = require("@marko/compiler");
|
||||||
var Walker = require("./Walker");
|
|
||||||
var Parser = require("./Parser");
|
|
||||||
var HtmlJsParser = require("./HtmlJsParser");
|
|
||||||
var Builder = require("./Builder");
|
|
||||||
var extend = require("raptor-util/extend");
|
var extend = require("raptor-util/extend");
|
||||||
var CompileContext = require("./CompileContext");
|
|
||||||
var globalConfig = require("./config");
|
var globalConfig = require("./config");
|
||||||
var ok = require("assert").ok;
|
var ok = require("assert").ok;
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var taglib = require("../taglib");
|
var taglib = require("../taglib");
|
||||||
var defaults = extend({}, globalConfig);
|
var defaults = extend({}, globalConfig);
|
||||||
|
|
||||||
Object.defineProperty(exports, "defaultOptions", {
|
var defaultOptionsExportDefinition = {
|
||||||
get: function() {
|
get: function() {
|
||||||
return globalConfig;
|
return globalConfig;
|
||||||
},
|
},
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: false
|
configurable: false
|
||||||
});
|
};
|
||||||
|
|
||||||
Object.defineProperty(exports, "config", {
|
Object.defineProperties(exports, {
|
||||||
get: function() {
|
defaultOptions: defaultOptionsExportDefinition,
|
||||||
return globalConfig;
|
config: defaultOptionsExportDefinition
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var defaultParser = new Parser(new HtmlJsParser());
|
|
||||||
|
|
||||||
function configure(newConfig) {
|
function configure(newConfig) {
|
||||||
if (!newConfig) {
|
if (!newConfig) {
|
||||||
newConfig = {};
|
newConfig = {};
|
||||||
@ -38,65 +28,36 @@ function configure(newConfig) {
|
|||||||
|
|
||||||
globalConfig = extend({}, defaults);
|
globalConfig = extend({}, defaults);
|
||||||
extend(globalConfig, newConfig);
|
extend(globalConfig, newConfig);
|
||||||
|
|
||||||
|
compiler.configure(newConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultCompiler = new Compiler({
|
function resultCompat({ code, meta }, options = {}) {
|
||||||
parser: defaultParser,
|
if (options.sourceOnly !== false) {
|
||||||
builder: Builder.DEFAULT_BUILDER
|
return code;
|
||||||
});
|
} else {
|
||||||
|
return { code, meta };
|
||||||
function createBuilder(options) {
|
}
|
||||||
return new Builder(options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWalker(options) {
|
function _compile(src, filename, userConfig, callback) {
|
||||||
return new Walker(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isXML(path) {
|
|
||||||
return path.endsWith(".xml") || path.endsWith(".xml.marko");
|
|
||||||
}
|
|
||||||
|
|
||||||
function _compile(src, filename, userOptions, callback) {
|
|
||||||
registerCoreTaglibs();
|
|
||||||
|
|
||||||
ok(filename, '"filename" argument is required');
|
ok(filename, '"filename" argument is required');
|
||||||
ok(typeof filename === "string", '"filename" argument should be a string');
|
ok(typeof filename === "string", '"filename" argument should be a string');
|
||||||
|
|
||||||
var options = {};
|
var options = {};
|
||||||
|
|
||||||
extend(options, globalConfig);
|
extend(options, globalConfig);
|
||||||
|
|
||||||
if (userOptions) {
|
if (userConfig) {
|
||||||
extend(options, userOptions);
|
extend(options, userConfig);
|
||||||
}
|
|
||||||
|
|
||||||
var compiler = defaultCompiler;
|
|
||||||
|
|
||||||
if (isXML(filename)) {
|
|
||||||
require("complain")("Using Marko to build XML is deprecated");
|
|
||||||
options.ignoreUnrecognizedTags = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const context = new CompileContext(src, filename, compiler.builder, options);
|
|
||||||
|
|
||||||
let result;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const compiled = compiler.compile(src, context);
|
|
||||||
result = userOptions.sourceOnly ? compiled.code : compiled;
|
|
||||||
} catch (e) {
|
|
||||||
if (callback) {
|
|
||||||
return callback(e);
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(null, result);
|
compiler.compile(src, filename, options).then(
|
||||||
|
result => callback(null, resultCompat(result, options)),
|
||||||
|
error => callback(error)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return resultCompat(compiler.compileSync(src, filename, options), options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +83,6 @@ function compileForBrowser(src, filename, options, callback) {
|
|||||||
{
|
{
|
||||||
output: "vdom",
|
output: "vdom",
|
||||||
meta: false,
|
meta: false,
|
||||||
browser: true,
|
|
||||||
sourceOnly: false
|
sourceOnly: false
|
||||||
},
|
},
|
||||||
options
|
options
|
||||||
@ -160,144 +120,49 @@ function compileFileForBrowser(filename, options, callback) {
|
|||||||
options = null;
|
options = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
options = extend(
|
options = extend({ output: "vdom", meta: false, sourceOnly: false }, options);
|
||||||
{ output: "vdom", meta: false, browser: true, sourceOnly: false },
|
|
||||||
options
|
|
||||||
);
|
|
||||||
return compileFile(filename, options, callback);
|
return compileFile(filename, options, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkUpToDate(/*templateFile, templateJsFile*/) {
|
|
||||||
return false; // TODO Implement checkUpToDate
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLastModified(path, options, callback) {
|
|
||||||
if (typeof options === "function") {
|
|
||||||
callback = options;
|
|
||||||
options = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, -1); // TODO Implement getLastModified
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearCaches() {
|
|
||||||
taglib.clearCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseRaw(templateSrc, filename, options) {
|
|
||||||
return parse(
|
|
||||||
templateSrc,
|
|
||||||
filename,
|
|
||||||
Object.assign(
|
|
||||||
{
|
|
||||||
raw: true,
|
|
||||||
ignorePlaceholders: true
|
|
||||||
},
|
|
||||||
options
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parse(templateSrc, filename, options) {
|
|
||||||
registerCoreTaglibs();
|
|
||||||
var context = new CompileContext(
|
|
||||||
templateSrc,
|
|
||||||
filename,
|
|
||||||
Builder.DEFAULT_BUILDER
|
|
||||||
);
|
|
||||||
|
|
||||||
if (options.onContext) {
|
|
||||||
options.onContext(context);
|
|
||||||
}
|
|
||||||
var parsed = defaultParser.parse(templateSrc, context, options);
|
|
||||||
|
|
||||||
if (context.hasErrors()) {
|
|
||||||
var errors = context.getErrors();
|
|
||||||
|
|
||||||
var message =
|
|
||||||
'An error occurred while trying to parse template at path "' +
|
|
||||||
filename +
|
|
||||||
'". Error(s) in template:\n';
|
|
||||||
for (var i = 0, len = errors.length; i < len; i++) {
|
|
||||||
let error = errors[i];
|
|
||||||
message += i + 1 + ") " + error.toString() + "\n";
|
|
||||||
}
|
|
||||||
var error = new Error(message);
|
|
||||||
error.errors = errors;
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.createBuilder = createBuilder;
|
|
||||||
exports.compileFile = compileFile;
|
exports.compileFile = compileFile;
|
||||||
exports.compile = compile;
|
exports.compile = compile;
|
||||||
exports.compileForBrowser = compileForBrowser;
|
exports.compileForBrowser = compileForBrowser;
|
||||||
exports.compileFileForBrowser = compileFileForBrowser;
|
exports.compileFileForBrowser = compileFileForBrowser;
|
||||||
exports.parseRaw = parseRaw;
|
|
||||||
exports.parse = parse;
|
|
||||||
|
|
||||||
exports.checkUpToDate = checkUpToDate;
|
|
||||||
exports.getLastModified = getLastModified;
|
|
||||||
exports.createWalker = createWalker;
|
|
||||||
exports.builder = Builder.DEFAULT_BUILDER;
|
|
||||||
exports.configure = configure;
|
exports.configure = configure;
|
||||||
exports.clearCaches = clearCaches;
|
|
||||||
|
|
||||||
exports.taglibLookup = taglib.lookup;
|
// TODO: resolve these circular dep issues.
|
||||||
exports.taglibLoader = taglib.loader;
|
Object.defineProperties(exports, {
|
||||||
exports.taglibFinder = taglib.finder;
|
taglibLookup: {
|
||||||
|
get() {
|
||||||
var coreTaglibsRegistered = false;
|
return taglib.lookup;
|
||||||
|
}
|
||||||
function registerCoreTaglibs() {
|
},
|
||||||
if (!coreTaglibsRegistered) {
|
taglibLoader: {
|
||||||
coreTaglibsRegistered = true;
|
get() {
|
||||||
taglib.register(
|
return taglib.loader;
|
||||||
require("../core-tags/cache/marko.json"),
|
}
|
||||||
require.resolve("../core-tags/cache/marko.json")
|
},
|
||||||
);
|
taglibFinder: {
|
||||||
taglib.register(
|
get() {
|
||||||
require("../core-tags/components/marko.json"),
|
return taglib.finder;
|
||||||
require.resolve("../core-tags/components/marko.json")
|
}
|
||||||
);
|
},
|
||||||
taglib.register(
|
buildTaglibLookup: {
|
||||||
require("../core-tags/core/marko.json"),
|
get() {
|
||||||
require.resolve("../core-tags/core/marko.json")
|
return compiler.taglib.buildLookup;
|
||||||
);
|
}
|
||||||
taglib.register(
|
|
||||||
require("../core-tags/html/marko.json"),
|
|
||||||
require.resolve("../core-tags/html/marko.json")
|
|
||||||
);
|
|
||||||
taglib.register(
|
|
||||||
require("../core-tags/migrate/marko.json"),
|
|
||||||
require.resolve("../core-tags/migrate/marko.json")
|
|
||||||
);
|
|
||||||
taglib.register(
|
|
||||||
require("../core-tags/svg/marko.json"),
|
|
||||||
require.resolve("../core-tags/svg/marko.json")
|
|
||||||
);
|
|
||||||
taglib.register(
|
|
||||||
require("../core-tags/math/marko.json"),
|
|
||||||
require.resolve("../core-tags/math/marko.json")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
function buildTaglibLookup(dirname) {
|
exports.clearCaches = function clearCaches() {
|
||||||
registerCoreTaglibs();
|
taglib.clearCache();
|
||||||
return taglib.buildLookup(dirname);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
exports.buildTaglibLookup = buildTaglibLookup;
|
|
||||||
|
|
||||||
exports.registerTaglib = function(filePath) {
|
exports.registerTaglib = function(filePath) {
|
||||||
registerCoreTaglibs();
|
|
||||||
|
|
||||||
ok(typeof filePath === "string", '"filePath" should be a string');
|
ok(typeof filePath === "string", '"filePath" should be a string');
|
||||||
taglib.registerFromFile(filePath);
|
taglib.registerFromFile(filePath);
|
||||||
clearCaches();
|
exports.clearCaches();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.isVDOMSupported = true;
|
exports.isVDOMSupported = true;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
var nativeRequire = require;
|
var nativeRequire = require;
|
||||||
var resolveFrom = require("resolve-from");
|
var resolveFrom = require("resolve-from");
|
||||||
var deresolve = require("./util/deresolve");
|
var deresolve = require("deresolve");
|
||||||
|
|
||||||
const deresolveOptions = {
|
const deresolveOptions = {
|
||||||
shouldRemoveExt(ext) {
|
shouldRemoveExt(ext) {
|
||||||
|
|||||||
5
packages/marko/src/core-tags/.eslintrc
Normal file
5
packages/marko/src/core-tags/.eslintrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"browser": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"browser": {
|
"browser": {
|
||||||
"./component-globals-tag.js": "./component-globals-tag-browser.js",
|
"./component-globals-tag.js": "./component-globals-tag-browser.js",
|
||||||
"./getRequirePath.js": "./getRequirePath-browser.js",
|
|
||||||
"./init-components-tag.js": "./init-components-tag-browser.js",
|
"./init-components-tag.js": "./init-components-tag-browser.js",
|
||||||
"./preserve-tag.js": "./preserve-tag-browser.js"
|
"./preserve-tag.js": "./preserve-tag-browser.js"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// the following development and legacy apis should not be included
|
|
||||||
// when bundling the server with a tool like webpack
|
|
||||||
if (!process.env.BUNDLE) {
|
|
||||||
if (process.env.MARKO_HOT_RELOAD) {
|
|
||||||
require("./hot-reload").enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If process was launched with browser refresh then automatically
|
|
||||||
// enable browser-refresh
|
|
||||||
require("./browser-refresh").enable();
|
|
||||||
|
|
||||||
// Adds the template.getDependencies() method needed by older versions of lasso-marko
|
|
||||||
require("./runtime/components/legacy/dependencies/html");
|
|
||||||
}
|
|
||||||
|
|
||||||
function fixFlush() {
|
function fixFlush() {
|
||||||
try {
|
try {
|
||||||
var OutgoingMessage = require("http").OutgoingMessage;
|
var OutgoingMessage = require("http").OutgoingMessage;
|
||||||
|
|||||||
@ -1,7 +1,84 @@
|
|||||||
if (process.env.BUNDLE) {
|
"use strict";
|
||||||
// you cannot load templates dynamically within a bundle
|
|
||||||
// all templates should be pre-compiled as part of the bundle
|
var nodePath = require("path");
|
||||||
module.exports = function() {};
|
var fs = require("fs");
|
||||||
} else {
|
var Module = require("module").Module;
|
||||||
module.exports = require("./index-default");
|
var compilerPath = nodePath.join(__dirname, "../compiler");
|
||||||
|
var markoCompiler = require(compilerPath);
|
||||||
|
var cwd = process.cwd();
|
||||||
|
var fsOptions = { encoding: "utf8" };
|
||||||
|
|
||||||
|
module.exports = function load(templatePath, templateSrc, options) {
|
||||||
|
if (arguments.length === 1) {
|
||||||
|
return doLoad(templatePath);
|
||||||
|
} else if (arguments.length === 2) {
|
||||||
|
// see if second argument is templateSrc (a String)
|
||||||
|
// or options (an Object)
|
||||||
|
var lastArg = arguments[arguments.length - 1];
|
||||||
|
if (typeof lastArg === "string") {
|
||||||
|
return doLoad(templatePath, templateSrc);
|
||||||
|
} else {
|
||||||
|
var finalOptions = templateSrc;
|
||||||
|
return doLoad(templatePath, null, finalOptions);
|
||||||
|
}
|
||||||
|
} else if (arguments.length === 3) {
|
||||||
|
// assume function called according to function signature
|
||||||
|
return doLoad(templatePath, templateSrc, options);
|
||||||
|
} else {
|
||||||
|
throw new Error("Illegal arguments");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function loadSource(templatePath, compiledSrc) {
|
||||||
|
// Short-circuit loading if the template has already been cached in the Node.js require cache
|
||||||
|
var cached = require.cache[templatePath];
|
||||||
|
if (cached) {
|
||||||
|
return cached.exports;
|
||||||
|
}
|
||||||
|
|
||||||
|
var templateModule = new Module(templatePath, module);
|
||||||
|
templateModule.paths = Module._nodeModulePaths(
|
||||||
|
nodePath.dirname(templatePath)
|
||||||
|
);
|
||||||
|
templateModule.filename = templatePath;
|
||||||
|
|
||||||
|
Module._cache[templatePath] = templateModule;
|
||||||
|
|
||||||
|
templateModule._compile(compiledSrc, templatePath);
|
||||||
|
|
||||||
|
return templateModule.exports;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCachedTemplate(templatePath) {
|
||||||
|
var precompiledTemplatePath = templatePath + ".js";
|
||||||
|
var templateModule =
|
||||||
|
require.cache[templatePath] || require.cache[precompiledTemplatePath];
|
||||||
|
|
||||||
|
if (templateModule) {
|
||||||
|
return templateModule.exports;
|
||||||
|
} else if (fs.existsSync(precompiledTemplatePath)) {
|
||||||
|
return require(precompiledTemplatePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function doLoad(templatePath, templateSrc, options) {
|
||||||
|
options = Object.assign({}, markoCompiler.defaultOptions, options);
|
||||||
|
templatePath = nodePath.resolve(cwd, templatePath);
|
||||||
|
var template = getCachedTemplate(templatePath);
|
||||||
|
|
||||||
|
if (!template) {
|
||||||
|
if (templateSrc == null) {
|
||||||
|
templateSrc = fs.readFileSync(templatePath, fsOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
var compiledSrc = markoCompiler.compile(templateSrc, templatePath, options);
|
||||||
|
|
||||||
|
template = loadSource(templatePath, compiledSrc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template.default) {
|
||||||
|
template = template.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return template;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,66 +25,12 @@ function compile(templatePath, markoCompiler, compilerOptions) {
|
|||||||
compilerOptions = markoCompiler.defaultOptions;
|
compilerOptions = markoCompiler.defaultOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
var writeToDisk = compilerOptions.writeToDisk;
|
var templateSrc = fs.readFileSync(templatePath, fsReadOptions);
|
||||||
|
var compiledSrc = markoCompiler.compile(templateSrc, templatePath);
|
||||||
|
|
||||||
var templateSrc;
|
|
||||||
var compiledSrc;
|
|
||||||
|
|
||||||
if (writeToDisk === false) {
|
|
||||||
// Don't write the compiled template to disk. Instead, load it
|
|
||||||
// directly from the compiled source using the internals of the
|
|
||||||
// Node.js module loading system.
|
|
||||||
templateSrc = fs.readFileSync(templatePath, fsReadOptions);
|
|
||||||
compiledSrc = markoCompiler.compile(templateSrc, templatePath);
|
|
||||||
} else {
|
|
||||||
var targetFile = templatePath + ".js";
|
|
||||||
|
|
||||||
if (
|
|
||||||
markoCompiler.defaultOptions.assumeUpToDate &&
|
|
||||||
fs.existsSync(targetFile)
|
|
||||||
) {
|
|
||||||
// If the target file already exists and "assumeUpToDate" then just use the previously
|
|
||||||
// compiled template.
|
|
||||||
return fs.readFileSync(targetFile, fsReadOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
var targetDir = path.dirname(templatePath);
|
|
||||||
|
|
||||||
var isUpToDate = markoCompiler.checkUpToDate(targetFile);
|
|
||||||
|
|
||||||
if (isUpToDate) {
|
|
||||||
compiledSrc = fs.readFileSync(targetFile, fsReadOptions);
|
|
||||||
} else {
|
|
||||||
templateSrc = fs.readFileSync(templatePath, fsReadOptions);
|
|
||||||
compiledSrc = markoCompiler.compile(
|
|
||||||
templateSrc,
|
|
||||||
templatePath,
|
|
||||||
compilerOptions
|
|
||||||
);
|
|
||||||
|
|
||||||
// Write to a temporary file and move it into place to avoid problems
|
|
||||||
// assocatiated with multiple processes write to the same file. We only
|
|
||||||
// write the compiled source code to disk so that stack traces will
|
|
||||||
// be accurate.
|
|
||||||
var filename = path.basename(targetFile);
|
|
||||||
var tempFile = path.join(
|
|
||||||
targetDir,
|
|
||||||
"." + process.pid + "." + Date.now() + "." + filename
|
|
||||||
);
|
|
||||||
fs.writeFileSync(tempFile, compiledSrc, fsReadOptions);
|
|
||||||
fs.renameSync(tempFile, targetFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We attach a path to the compiled template so that hot reloading will work.
|
|
||||||
return compiledSrc;
|
return compiledSrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLoadedTemplate(path) {
|
|
||||||
var cached = require.cache[path];
|
|
||||||
return cached && cached.exports.render ? cached.exports : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function install(options) {
|
function install(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
@ -92,10 +38,7 @@ function install(options) {
|
|||||||
? options.require.extensions
|
? options.require.extensions
|
||||||
: require.extensions;
|
: require.extensions;
|
||||||
|
|
||||||
var compilerOptions = Object.assign(
|
var compilerOptions = options.compilerOptions;
|
||||||
{ requireTemplates: true },
|
|
||||||
options.compilerOptions
|
|
||||||
);
|
|
||||||
require("../compiler").configure(compilerOptions);
|
require("../compiler").configure(compilerOptions);
|
||||||
|
|
||||||
var extensions = [];
|
var extensions = [];
|
||||||
@ -113,15 +56,6 @@ function install(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function markoRequireExtension(module, filename) {
|
function markoRequireExtension(module, filename) {
|
||||||
var targetFile = filename + ".js";
|
|
||||||
var cachedTemplate =
|
|
||||||
getLoadedTemplate(targetFile) || getLoadedTemplate(filename);
|
|
||||||
if (cachedTemplate) {
|
|
||||||
// The template has already been loaded so use the exports of the already loaded template
|
|
||||||
module.exports = cachedTemplate;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve the appropriate compiler relative to the location of the
|
// Resolve the appropriate compiler relative to the location of the
|
||||||
// marko template file on disk using the "resolve-from" module.
|
// marko template file on disk using the "resolve-from" module.
|
||||||
var dirname = path.dirname(filename);
|
var dirname = path.dirname(filename);
|
||||||
@ -134,7 +68,7 @@ function install(options) {
|
|||||||
|
|
||||||
// Append ".js" to the filename since that is where we write the compiled
|
// Append ".js" to the filename since that is where we write the compiled
|
||||||
// source code that is being loaded. This allows stack traces to match up.
|
// source code that is being loaded. This allows stack traces to match up.
|
||||||
module._compile(compiledSrc, targetFile);
|
module._compile(compiledSrc, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
requireExtensions[MARKO_EXTENSIONS] =
|
requireExtensions[MARKO_EXTENSIONS] =
|
||||||
|
|||||||
5
packages/marko/src/runtime/.eslintrc
Normal file
5
packages/marko/src/runtime/.eslintrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"browser": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,6 +22,7 @@ var domData = require("./dom-data");
|
|||||||
var componentsByDOMNode = domData.___componentByDOMNode;
|
var componentsByDOMNode = domData.___componentByDOMNode;
|
||||||
var CONTEXT_KEY = "__subtree_context__";
|
var CONTEXT_KEY = "__subtree_context__";
|
||||||
|
|
||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
var slice = Array.prototype.slice;
|
var slice = Array.prototype.slice;
|
||||||
|
|
||||||
var COMPONENT_SUBSCRIBE_TO_OPTIONS;
|
var COMPONENT_SUBSCRIBE_TO_OPTIONS;
|
||||||
@ -97,7 +98,7 @@ function processUpdateHandlers(component, stateChanges, oldState) {
|
|||||||
var handlers;
|
var handlers;
|
||||||
|
|
||||||
for (var propName in stateChanges) {
|
for (var propName in stateChanges) {
|
||||||
if (stateChanges.hasOwnProperty(propName)) {
|
if (hasOwnProperty.call(stateChanges, propName)) {
|
||||||
var handlerMethodName = "update_" + propName;
|
var handlerMethodName = "update_" + propName;
|
||||||
|
|
||||||
handlerMethod = component[handlerMethodName];
|
handlerMethod = component[handlerMethodName];
|
||||||
@ -245,23 +246,19 @@ Component.prototype = componentProto = {
|
|||||||
},
|
},
|
||||||
getEl: function(key, index) {
|
getEl: function(key, index) {
|
||||||
if (key) {
|
if (key) {
|
||||||
var resolvedKey = resolveKeyHelper(key, index);
|
var keyedElement = this.___keyedElements[
|
||||||
var keyedElement = this.___keyedElements["@" + resolvedKey];
|
"@" + resolveKeyHelper(key, index)
|
||||||
|
];
|
||||||
|
|
||||||
if (!keyedElement) {
|
// eslint-disable-next-line no-constant-condition
|
||||||
var keyedComponentRoot = this.___keyedElements[resolvedKey];
|
if ("MARKO_DEBUG") {
|
||||||
|
if (
|
||||||
if (keyedComponentRoot) {
|
keyedElement &&
|
||||||
// eslint-disable-next-line no-constant-condition
|
keyedElement.nodeType !== 1 /* Node.ELEMENT_NODE */
|
||||||
if ("MARKO_DEBUG") {
|
) {
|
||||||
complain(
|
throw new Error(
|
||||||
"Accessing the elements of a child component using 'component.getEl' is deprecated."
|
"Using 'getEl(key)' to get a component instance is not supported, did you mean 'getComponent(key)'?"
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
return keyedComponentRoot.nodeType === 1 /** Node.ELEMENT_NODE */
|
|
||||||
? keyedComponentRoot
|
|
||||||
: walkFragments(keyedComponentRoot);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,20 +280,20 @@ Component.prototype = componentProto = {
|
|||||||
return els;
|
return els;
|
||||||
},
|
},
|
||||||
getComponent: function(key, index) {
|
getComponent: function(key, index) {
|
||||||
var rootNode = this.___keyedElements[resolveKeyHelper(key, index)];
|
var rootNode = this.___keyedElements["@" + resolveKeyHelper(key, index)];
|
||||||
if (/\[\]$/.test(key)) {
|
// eslint-disable-next-line no-constant-condition
|
||||||
// eslint-disable-next-line no-constant-condition
|
if ("MARKO_DEBUG") {
|
||||||
if ("MARKO_DEBUG") {
|
if (/\[\]$/.test(key)) {
|
||||||
complain(
|
throw new Error(
|
||||||
"A repeated key[] was passed to getComponent. Use a non-repeating key if there is only one of these components."
|
"A repeated key[] was passed to getComponent. Use a non-repeating key if there is only one of these components."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
rootNode = rootNode && rootNode[Object.keys(rootNode)[0]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rootNode && componentsByDOMNode.get(rootNode);
|
return rootNode && componentsByDOMNode.get(rootNode);
|
||||||
},
|
},
|
||||||
getComponents: function(key) {
|
getComponents: function(key) {
|
||||||
var lookup = this.___keyedElements[key + "[]"];
|
var lookup = this.___keyedElements["@" + key + "[]"];
|
||||||
return lookup
|
return lookup
|
||||||
? Object.keys(lookup)
|
? Object.keys(lookup)
|
||||||
.map(function(key) {
|
.map(function(key) {
|
||||||
@ -388,7 +385,7 @@ Component.prototype = componentProto = {
|
|||||||
// Merge in the new state with the old state
|
// Merge in the new state with the old state
|
||||||
var newState = name;
|
var newState = name;
|
||||||
for (var k in newState) {
|
for (var k in newState) {
|
||||||
if (newState.hasOwnProperty(k)) {
|
if (hasOwnProperty.call(newState, k)) {
|
||||||
state.___set(k, newState[k], true /* ensure:true */);
|
state.___set(k, newState[k], true /* ensure:true */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,21 +93,17 @@ ComponentDef.___deserialize = function(o, types, global, registry) {
|
|||||||
var input = o[2];
|
var input = o[2];
|
||||||
var extra = o[3];
|
var extra = o[3];
|
||||||
|
|
||||||
var isLegacy = extra.l;
|
|
||||||
var state = extra.s;
|
var state = extra.s;
|
||||||
var componentProps = extra.w;
|
var componentProps = extra.w;
|
||||||
var flags = extra.f;
|
var flags = extra.f;
|
||||||
|
|
||||||
var component =
|
var component = registry.___createComponent(typeName, id);
|
||||||
typeName /* legacy */ &&
|
|
||||||
registry.___createComponent(typeName, id, isLegacy);
|
|
||||||
|
|
||||||
// Prevent newly created component from being queued for update since we area
|
// Prevent newly created component from being queued for update since we area
|
||||||
// just building it from the server info
|
// just building it from the server info
|
||||||
component.___updateQueued = true;
|
component.___updateQueued = true;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!isLegacy &&
|
|
||||||
flags & FLAG_WILL_RERENDER_IN_BROWSER &&
|
flags & FLAG_WILL_RERENDER_IN_BROWSER &&
|
||||||
!(flags & FLAG_OLD_HYDRATE_NO_CREATE)
|
!(flags & FLAG_OLD_HYDRATE_NO_CREATE)
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -13,22 +13,17 @@ module.exports = function beginComponent(
|
|||||||
key,
|
key,
|
||||||
ownerComponentDef,
|
ownerComponentDef,
|
||||||
isSplitComponent,
|
isSplitComponent,
|
||||||
isImplicitComponent,
|
isImplicitComponent
|
||||||
existingComponentDef
|
|
||||||
) {
|
) {
|
||||||
var globalContext = componentsContext.___globalContext;
|
var globalContext = componentsContext.___globalContext;
|
||||||
|
|
||||||
var componentId = component.id;
|
var componentId = component.id;
|
||||||
|
|
||||||
// existingComponentDef is only here to allow binding a conditional
|
var componentDef = (componentsContext.___componentDef = new ComponentDef(
|
||||||
// widget. It should be removed when the legacy compat layer is removed.
|
component,
|
||||||
var componentDef =
|
componentId,
|
||||||
existingComponentDef ||
|
globalContext
|
||||||
(componentsContext.___componentDef = new ComponentDef(
|
));
|
||||||
component,
|
|
||||||
componentId,
|
|
||||||
globalContext
|
|
||||||
));
|
|
||||||
|
|
||||||
// On the server
|
// On the server
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -89,7 +89,6 @@ function addComponentsFromContext(componentsContext, componentsToHydrate) {
|
|||||||
d: componentDef.___domEvents,
|
d: componentDef.___domEvents,
|
||||||
e: customEvents,
|
e: customEvents,
|
||||||
f: flags ? flags : undefined,
|
f: flags ? flags : undefined,
|
||||||
l: componentDef.___isLegacy,
|
|
||||||
p: customEvents && scope, // Only serialize scope if we need to attach custom events
|
p: customEvents && scope, // Only serialize scope if we need to attach custom events
|
||||||
r: componentDef.___boundary,
|
r: componentDef.___boundary,
|
||||||
s: state,
|
s: state,
|
||||||
|
|||||||
@ -164,10 +164,6 @@ function addDOMEventListeners(
|
|||||||
function initComponent(componentDef, doc) {
|
function initComponent(componentDef, doc) {
|
||||||
var component = componentDef.___component;
|
var component = componentDef.___component;
|
||||||
|
|
||||||
if (!component || !component.___isComponent) {
|
|
||||||
return; // legacy
|
|
||||||
}
|
|
||||||
|
|
||||||
component.___reset();
|
component.___reset();
|
||||||
component.___document = doc;
|
component.___document = doc;
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,6 @@
|
|||||||
"./endComponent.js": "./endComponent-browser.js",
|
"./endComponent.js": "./endComponent-browser.js",
|
||||||
"./index.js": "./index-browser.js",
|
"./index.js": "./index-browser.js",
|
||||||
"./init-components.js": "./init-components-browser.js",
|
"./init-components.js": "./init-components-browser.js",
|
||||||
"./legacy/defineWidget-legacy.js":
|
|
||||||
"./legacy/defineWidget-legacy-browser.js",
|
|
||||||
"./registry.js": "./registry-browser.js",
|
"./registry.js": "./registry-browser.js",
|
||||||
"./util.js": "./util-browser.js"
|
"./util.js": "./util-browser.js"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,8 +19,6 @@
|
|||||||
- Fixes for IE <=10
|
- Fixes for IE <=10
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* globals window */
|
|
||||||
|
|
||||||
var isReady = false;
|
var isReady = false;
|
||||||
var readyBound = false;
|
var readyBound = false;
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
var complain = "MARKO_DEBUG" && require("complain");
|
|
||||||
var defineComponent = require("./defineComponent");
|
var defineComponent = require("./defineComponent");
|
||||||
var loader = require("../../loader");
|
|
||||||
require(".");
|
require(".");
|
||||||
|
|
||||||
var registered = {};
|
var registered = {};
|
||||||
@ -14,23 +12,13 @@ function register(componentId, def) {
|
|||||||
return componentId;
|
return componentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function load(typeName, isLegacy) {
|
function load(typeName) {
|
||||||
var target = loaded[typeName];
|
var target = loaded[typeName];
|
||||||
if (!target) {
|
if (!target) {
|
||||||
target = registered[typeName];
|
target = registered[typeName];
|
||||||
|
|
||||||
if (target) {
|
if (target) {
|
||||||
target = target();
|
target = target();
|
||||||
} else if (isLegacy) {
|
|
||||||
target = window.$markoLegacy.load(typeName);
|
|
||||||
} else {
|
|
||||||
target = loader(typeName);
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
|
||||||
if ("MARKO_DEBUG") {
|
|
||||||
complain(
|
|
||||||
"Looks like you used `require:` in your browser.json to load a component. This requires that Marko has knowledge of how lasso generates paths and will be removed in a future version. `marko-dependencies:/path/to/template.marko` should be used instead."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!target) {
|
if (!target) {
|
||||||
@ -43,14 +31,14 @@ function load(typeName, isLegacy) {
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getComponentClass(typeName, isLegacy) {
|
function getComponentClass(typeName) {
|
||||||
var ComponentClass = componentTypes[typeName];
|
var ComponentClass = componentTypes[typeName];
|
||||||
|
|
||||||
if (ComponentClass) {
|
if (ComponentClass) {
|
||||||
return ComponentClass;
|
return ComponentClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentClass = load(typeName, isLegacy);
|
ComponentClass = load(typeName);
|
||||||
|
|
||||||
ComponentClass = ComponentClass.Component || ComponentClass;
|
ComponentClass = ComponentClass.Component || ComponentClass;
|
||||||
|
|
||||||
@ -94,8 +82,8 @@ function getComponentClass(typeName, isLegacy) {
|
|||||||
return ComponentClass;
|
return ComponentClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createComponent(typeName, id, isLegacy) {
|
function createComponent(typeName, id) {
|
||||||
var ComponentClass = getComponentClass(typeName, isLegacy);
|
var ComponentClass = getComponentClass(typeName);
|
||||||
return new ComponentClass(id);
|
return new ComponentClass(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -221,7 +221,3 @@ function createRendererFunc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = createRendererFunc;
|
module.exports = createRendererFunc;
|
||||||
|
|
||||||
// exports used by the legacy renderer
|
|
||||||
createRendererFunc.___resolveComponentKey = resolveComponentKey;
|
|
||||||
createRendererFunc.___trackAsyncComponents = trackAsyncComponents;
|
|
||||||
|
|||||||
@ -6,16 +6,6 @@ function nextComponentIdProvider(out) {
|
|||||||
var prefix = out.global.componentIdPrefix || out.global.widgetIdPrefix || "s"; // "s" is for server (we use "b" for the browser)
|
var prefix = out.global.componentIdPrefix || out.global.widgetIdPrefix || "s"; // "s" is for server (we use "b" for the browser)
|
||||||
var nextId = 0;
|
var nextId = 0;
|
||||||
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
|
||||||
if ("MARKO_DEBUG") {
|
|
||||||
if (out.global.widgetIdPrefix) {
|
|
||||||
require("complain")(
|
|
||||||
"$global.widgetIdPrefix is deprecated. use $global.componentIdPrefix instead.",
|
|
||||||
{ location: false }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return function nextComponentId() {
|
return function nextComponentId() {
|
||||||
return prefix + nextId++;
|
return prefix + nextId++;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges object properties
|
* Merges object properties
|
||||||
*/
|
*/
|
||||||
@ -9,7 +11,7 @@ module.exports = function assign() {
|
|||||||
var source = arguments[i];
|
var source = arguments[i];
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
for (var k in source) {
|
for (var k in source) {
|
||||||
if (source.hasOwnProperty(k)) {
|
if (hasOwnProperty.call(source, k)) {
|
||||||
into[k] = source[k];
|
into[k] = source[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,13 +27,13 @@ module.exports = function dynamicTag(
|
|||||||
customEvents
|
customEvents
|
||||||
) {
|
) {
|
||||||
if (tag) {
|
if (tag) {
|
||||||
|
if (tag.default) {
|
||||||
|
tag = tag.default;
|
||||||
|
}
|
||||||
|
|
||||||
var attrs = getAttrs && getAttrs();
|
var attrs = getAttrs && getAttrs();
|
||||||
var component = componentDef && componentDef.___component;
|
var component = componentDef && componentDef.___component;
|
||||||
if (typeof tag === "string") {
|
if (typeof tag === "string") {
|
||||||
if (isNaN(key)) {
|
|
||||||
key = "@" + key;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (customEvents) {
|
if (customEvents) {
|
||||||
if (!props) {
|
if (!props) {
|
||||||
props = {};
|
props = {};
|
||||||
@ -93,18 +93,14 @@ module.exports = function dynamicTag(
|
|||||||
var render = (tag && tag.renderBody) || tag;
|
var render = (tag && tag.renderBody) || tag;
|
||||||
var isFn = typeof render === "function";
|
var isFn = typeof render === "function";
|
||||||
|
|
||||||
if (render.safeHTML) {
|
// eslint-disable-next-line no-constant-condition
|
||||||
// eslint-disable-next-line no-constant-condition
|
if ("MARKO_DEBUG") {
|
||||||
if ("MARKO_DEBUG") {
|
if (render.safeHTML || render.toHTML) {
|
||||||
complain(
|
throw new Error(
|
||||||
"Using `<include(x)/>` or the `<${dynamic}/>` tags with a `{ safeHTML: ... }` object is deprecated. Use the unescaped text placeholder syntax instead."
|
"Using `<include(x)/>` or the `<${dynamic}/>` tags with a `{ safeHTML: ... }` object is no longer supported. Use the unescaped text placeholder syntax instead."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.write(tag.safeHTML);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFn) {
|
if (isFn) {
|
||||||
var flags = componentDef ? componentDef.___flags : 0;
|
var flags = componentDef ? componentDef.___flags : 0;
|
||||||
var willRerender = flags & FLAG_WILL_RERENDER_IN_BROWSER;
|
var willRerender = flags & FLAG_WILL_RERENDER_IN_BROWSER;
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges object properties
|
* Merges object properties
|
||||||
*/
|
*/
|
||||||
module.exports = function merge(into, source) {
|
module.exports = function merge(into, source) {
|
||||||
for (var k in source) {
|
for (var k in source) {
|
||||||
if (source.hasOwnProperty(k) && !into.hasOwnProperty(k)) {
|
if (hasOwnProperty.call(source, k) && !hasOwnProperty.call(into, k)) {
|
||||||
into[k] = source[k];
|
into[k] = source[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -219,8 +219,6 @@ var proto = (AsyncStream.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
state.events.emit("beginAsync", {
|
state.events.emit("beginAsync", {
|
||||||
writer: newStream, // Legacy
|
|
||||||
parentWriter: this, // Legacy
|
|
||||||
out: newStream,
|
out: newStream,
|
||||||
parentOut: this
|
parentOut: this
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
var escape = require("./escape-xml");
|
var escape = require("./escape-xml");
|
||||||
var escapeDoubleQuotes = escape.d;
|
var escapeDoubleQuotes = escape.d;
|
||||||
var escapeSingleQuotes = escape.s;
|
|
||||||
var complain = "MARKO_DEBUG" && require("complain");
|
|
||||||
|
|
||||||
module.exports = function attr(name, value) {
|
module.exports = function attr(name, value) {
|
||||||
if (value == null || value === false) {
|
if (value == null || value === false) {
|
||||||
@ -16,28 +14,14 @@ module.exports = function attr(name, value) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = typeof value;
|
|
||||||
result += "=";
|
result += "=";
|
||||||
|
|
||||||
if (type === "number") {
|
if (typeof value === "number") {
|
||||||
return result + value;
|
return result + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == "object") {
|
if (value instanceof RegExp) {
|
||||||
switch (value.toString) {
|
return result + doubleQuote(value.source);
|
||||||
case Object.prototype.toString:
|
|
||||||
case Array.prototype.toString:
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
|
||||||
if ("MARKO_DEBUG") {
|
|
||||||
complain(
|
|
||||||
"Relying on JSON.stringify for attribute values is deprecated, in future versions of Marko these will be cast to strings instead."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result + singleQuote(JSON.stringify(value));
|
|
||||||
case RegExp.prototype.toString:
|
|
||||||
return result + doubleQuote(value.source);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result + doubleQuote(value);
|
return result + doubleQuote(value);
|
||||||
@ -46,7 +30,3 @@ module.exports = function attr(name, value) {
|
|||||||
function doubleQuote(value) {
|
function doubleQuote(value) {
|
||||||
return '"' + escapeDoubleQuotes(value) + '"';
|
return '"' + escapeDoubleQuotes(value) + '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
function singleQuote(value) {
|
|
||||||
return "'" + escapeSingleQuotes(value) + "'";
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var complain = "MARKO_DEBUG" && require("complain");
|
|
||||||
var changeCase = require("../../helpers/_change-case");
|
var changeCase = require("../../helpers/_change-case");
|
||||||
var attrHelper = require("./attr");
|
var attrHelper = require("./attr");
|
||||||
var classAttrHelper = require("./class-attr");
|
var classAttrHelper = require("./class-attr");
|
||||||
@ -11,31 +10,34 @@ var invalidAttrNameCharacters = /[\s'"</=\\]/u;
|
|||||||
var validAttrs = Object.create(null);
|
var validAttrs = Object.create(null);
|
||||||
var invalidAttrs = Object.create(null);
|
var invalidAttrs = Object.create(null);
|
||||||
|
|
||||||
module.exports = function attrs(arg) {
|
module.exports = function attrs(attributes) {
|
||||||
if (typeof arg === "object") {
|
if (attributes != null) {
|
||||||
var out = "";
|
// eslint-disable-next-line no-constant-condition
|
||||||
for (var attrName in arg) {
|
if ("MARKO_DEBUG") {
|
||||||
if (attrName === "style") {
|
if (typeof attributes !== "object") {
|
||||||
out += styleAttrHelper(arg[attrName]);
|
throw new Error(
|
||||||
} else if (attrName === "class") {
|
"A non object was passed as a dynamic attributes value."
|
||||||
out += classAttrHelper(arg[attrName]);
|
|
||||||
} else if (attrName !== "renderBody" && isValidAttrName(attrName)) {
|
|
||||||
out += attrHelper(
|
|
||||||
changeCase.___camelToDashCase(attrName),
|
|
||||||
arg[attrName]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
} else if (typeof arg === "string") {
|
var result = "";
|
||||||
// eslint-disable-next-line no-constant-condition
|
|
||||||
if ("MARKO_DEBUG") {
|
for (var attrName in attributes) {
|
||||||
complain(
|
if (attrName === "style") {
|
||||||
"Passing a string as a dynamic attribute value is deprecated - More details: https://github.com/marko-js/marko/wiki/Deprecation:-String-as-dynamic-attribute-value"
|
result += styleAttrHelper(attributes[attrName]);
|
||||||
);
|
} else if (attrName === "class") {
|
||||||
|
result += classAttrHelper(attributes[attrName]);
|
||||||
|
} else if (attrName !== "renderBody" && isValidAttrName(attrName)) {
|
||||||
|
result += attrHelper(
|
||||||
|
changeCase.___camelToDashCase(attrName),
|
||||||
|
attributes[attrName]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return arg;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,38 +1,33 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var complain = "MARKO_DEBUG" && require("complain");
|
|
||||||
var attrsHelper = require("./attrs");
|
var attrsHelper = require("./attrs");
|
||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges attribute objects into a string.
|
* Merges attribute objects into a string.
|
||||||
*/
|
*/
|
||||||
module.exports = function mergeAttrs() {
|
module.exports = function mergeAttrs() {
|
||||||
var result = "";
|
var result = "";
|
||||||
var currentAttrs = {};
|
var finalAttributes = {};
|
||||||
for (var i = 0; i < arguments.length; i++) {
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
var source = arguments[i];
|
var attributes = arguments[i];
|
||||||
if (typeof source === "string") {
|
if (attributes != null) {
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
if ("MARKO_DEBUG") {
|
if ("MARKO_DEBUG") {
|
||||||
complain(
|
if (typeof attributes !== "object") {
|
||||||
"Passing a string as dynamic attributes ('<div ${string}>' or '<div ...string>') is deprecated, use an object instead."
|
throw new Error(
|
||||||
);
|
"A non object was passed as a dynamic attributes value."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source[0] !== " ") {
|
for (var k in attributes) {
|
||||||
source = " " + source;
|
if (hasOwnProperty.call(attributes, k)) {
|
||||||
}
|
finalAttributes[k] = attributes[k];
|
||||||
|
|
||||||
result += attrsHelper(currentAttrs) + source;
|
|
||||||
currentAttrs = {};
|
|
||||||
} else if (source != null) {
|
|
||||||
for (var k in source) {
|
|
||||||
if (source.hasOwnProperty(k)) {
|
|
||||||
currentAttrs[k] = source[k];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result + attrsHelper(currentAttrs);
|
return result + attrsHelper(finalAttributes);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* globals window */
|
|
||||||
|
|
||||||
var win = window;
|
var win = window;
|
||||||
var setImmediate = win.setImmediate;
|
var setImmediate = win.setImmediate;
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* jshint newcap:false */
|
/* jshint newcap:false */
|
||||||
|
|
||||||
var complain = "MARKO_DEBUG" && require("complain");
|
|
||||||
var domData = require("../components/dom-data");
|
var domData = require("../components/dom-data");
|
||||||
var vElementByDOMNode = domData.___vElementByDOMNode;
|
var vElementByDOMNode = domData.___vElementByDOMNode;
|
||||||
var VNode = require("./VNode");
|
var VNode = require("./VNode");
|
||||||
var inherit = require("raptor-util/inherit");
|
var inherit = require("raptor-util/inherit");
|
||||||
var ATTR_XLINK_HREF = "xlink:href";
|
var ATTR_XLINK_HREF = "xlink:href";
|
||||||
var xmlnsRegExp = /^xmlns(:|$)/;
|
var xmlnsRegExp = /^xmlns(:|$)/;
|
||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
var NS_XLINK = "http://www.w3.org/1999/xlink";
|
var NS_XLINK = "http://www.w3.org/1999/xlink";
|
||||||
var NS_HTML = "http://www.w3.org/1999/xhtml";
|
var NS_HTML = "http://www.w3.org/1999/xhtml";
|
||||||
var NS_MATH = "http://www.w3.org/1998/Math/MathML";
|
var NS_MATH = "http://www.w3.org/1998/Math/MathML";
|
||||||
@ -28,18 +28,8 @@ function convertAttrValue(type, value) {
|
|||||||
if (value === true) {
|
if (value === true) {
|
||||||
return "";
|
return "";
|
||||||
} else if (type == "object") {
|
} else if (type == "object") {
|
||||||
switch (value.toString) {
|
if (value instanceof RegExp) {
|
||||||
case Object.prototype.toString:
|
return value.source;
|
||||||
case Array.prototype.toString:
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
|
||||||
if ("MARKO_DEBUG") {
|
|
||||||
complain(
|
|
||||||
"Relying on JSON.stringify for attribute values is deprecated, in future versions of Marko these will be cast to strings instead."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return JSON.stringify(value);
|
|
||||||
case RegExp.prototype.toString:
|
|
||||||
return value.source;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +38,7 @@ function convertAttrValue(type, value) {
|
|||||||
|
|
||||||
function assign(a, b) {
|
function assign(a, b) {
|
||||||
for (var key in b) {
|
for (var key in b) {
|
||||||
if (b.hasOwnProperty(key)) {
|
if (hasOwnProperty.call(b, key)) {
|
||||||
a[key] = b[key];
|
a[key] = b[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var complain = "MARKO_DEBUG" && require("complain");
|
|
||||||
var changeCase = require("../../helpers/_change-case");
|
var changeCase = require("../../helpers/_change-case");
|
||||||
var classHelper = require("../../helpers/class-value");
|
var classHelper = require("../../helpers/class-value");
|
||||||
var styleHelper = require("../../helpers/style-value");
|
var styleHelper = require("../../helpers/style-value");
|
||||||
@ -9,17 +8,16 @@ var styleHelper = require("../../helpers/style-value");
|
|||||||
* Helper for processing dynamic attributes
|
* Helper for processing dynamic attributes
|
||||||
*/
|
*/
|
||||||
module.exports = function(attributes) {
|
module.exports = function(attributes) {
|
||||||
if (typeof attributes === "string") {
|
if (attributes != null) {
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
if ("MARKO_DEBUG") {
|
if ("MARKO_DEBUG") {
|
||||||
complain(
|
if (typeof attributes !== "object") {
|
||||||
"Passing a string as a dynamic attribute value is deprecated - More details: https://github.com/marko-js/marko/wiki/Deprecation:-String-as-dynamic-attribute-value"
|
throw new Error(
|
||||||
);
|
"A non object was passed as a dynamic attributes value."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return parseAttrs(attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attributes) {
|
|
||||||
var newAttributes = {};
|
var newAttributes = {};
|
||||||
|
|
||||||
for (var attrName in attributes) {
|
for (var attrName in attributes) {
|
||||||
@ -44,23 +42,3 @@ module.exports = function(attributes) {
|
|||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
};
|
};
|
||||||
|
|
||||||
var parseContainer;
|
|
||||||
function parseAttrs(str) {
|
|
||||||
if (str === "") {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
parseContainer = parseContainer || document.createElement("div");
|
|
||||||
parseContainer.innerHTML = "<a " + str + ">";
|
|
||||||
var attrs = parseContainer.firstChild.attributes;
|
|
||||||
var result = {};
|
|
||||||
var attr;
|
|
||||||
|
|
||||||
for (var len = attrs.length, i = 0; i < len; i++) {
|
|
||||||
attr = attrs[i];
|
|
||||||
result[attr.name] = attr.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -2,10 +2,11 @@
|
|||||||
var taglibLoader = require("../taglib-loader");
|
var taglibLoader = require("../taglib-loader");
|
||||||
var nodePath = require("path");
|
var nodePath = require("path");
|
||||||
var lassoPackageRoot = require("lasso-package-root");
|
var lassoPackageRoot = require("lasso-package-root");
|
||||||
var resolveFrom = require("resolve-from");
|
var resolveFrom = require("resolve-from").silent;
|
||||||
var scanTagsDir = require("../taglib-loader/scanTagsDir");
|
var scanTagsDir = require("../taglib-loader/scanTagsDir");
|
||||||
var DependencyChain = require("../taglib-loader/DependencyChain");
|
var DependencyChain = require("../taglib-loader/DependencyChain");
|
||||||
var lassoCachingFS = require("lasso-caching-fs");
|
var lassoCachingFS = require("lasso-caching-fs");
|
||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
var findCache = {};
|
var findCache = {};
|
||||||
var excludedDirs = {};
|
var excludedDirs = {};
|
||||||
@ -70,7 +71,7 @@ function find(dirname, registeredTaglibs) {
|
|||||||
|
|
||||||
var helper = {
|
var helper = {
|
||||||
alreadyAdded: function(taglibPath) {
|
alreadyAdded: function(taglibPath) {
|
||||||
return added.hasOwnProperty(taglibPath);
|
return hasOwnProperty.call(added, taglibPath);
|
||||||
},
|
},
|
||||||
addTaglib: function(taglib) {
|
addTaglib: function(taglib) {
|
||||||
if (added[taglib.path]) {
|
if (added[taglib.path]) {
|
||||||
|
|||||||
@ -1,22 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var forEachEntry = require("raptor-util/forEachEntry");
|
var forEachEntry = require("raptor-util/forEachEntry");
|
||||||
var ok = require("assert").ok;
|
var ok = require("assert").ok;
|
||||||
var CustomTag;
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var markoModules = require("../../compiler/modules");
|
var markoModules = require("../../compiler/modules");
|
||||||
var complain = require("complain");
|
var complain = require("complain");
|
||||||
var coreTagsPath = path.join(__dirname, "../../core-tags");
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
function createCustomTag(el, tagDef) {
|
|
||||||
CustomTag = CustomTag || require("../../compiler/ast/CustomTag");
|
|
||||||
return new CustomTag(el, tagDef);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createCustomTagNodeFactory(tagDef) {
|
|
||||||
return function nodeFactory(el) {
|
|
||||||
return createCustomTag(el, tagDef);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class Tag {
|
class Tag {
|
||||||
constructor(filePath) {
|
constructor(filePath) {
|
||||||
@ -55,30 +43,6 @@ class Tag {
|
|||||||
// this._nodeFactory = undefined;
|
// this._nodeFactory = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DEPRECATED
|
|
||||||
*/
|
|
||||||
forEachVariable(callback, thisObj) {
|
|
||||||
if (!this.nestedVariables) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.nestedVariables.vars.forEach(callback, thisObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DEPRECATED
|
|
||||||
*/
|
|
||||||
forEachImportedVariable(callback, thisObj) {
|
|
||||||
if (!this.importedVariables) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
forEachEntry(this.importedVariables, function(key, importedVariable) {
|
|
||||||
callback.call(thisObj, importedVariable);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
forEachTransformer(callback, thisObj) {
|
forEachTransformer(callback, thisObj) {
|
||||||
forEachEntry(this.transformers, function(key, transformer) {
|
forEachEntry(this.transformers, function(key, transformer) {
|
||||||
callback.call(thisObj, transformer);
|
callback.call(thisObj, transformer);
|
||||||
@ -87,7 +51,7 @@ class Tag {
|
|||||||
hasTransformers() {
|
hasTransformers() {
|
||||||
/*jshint unused:false */
|
/*jshint unused:false */
|
||||||
for (var k in this.transformers) {
|
for (var k in this.transformers) {
|
||||||
if (this.transformers.hasOwnProperty(k)) {
|
if (hasOwnProperty.call(this.transformers, k)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,12 +60,6 @@ class Tag {
|
|||||||
|
|
||||||
checkDeprecatedAttr(attr) {
|
checkDeprecatedAttr(attr) {
|
||||||
attr.filePath = this.filePath;
|
attr.filePath = this.filePath;
|
||||||
if (attr.name === "key" && !this.isCoreTag()) {
|
|
||||||
complain("@key property is deprecated", {
|
|
||||||
location: this.filePath
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//
|
|
||||||
if (attr.setFlag && attr.setFlag !== "hasComponentEvents") {
|
if (attr.setFlag && attr.setFlag !== "hasComponentEvents") {
|
||||||
complain(`${attr.name} - : set-flag property is deprecated`, {
|
complain(`${attr.name} - : set-flag property is deprecated`, {
|
||||||
location: this.filePath
|
location: this.filePath
|
||||||
@ -130,17 +88,8 @@ class Tag {
|
|||||||
if (attr.name === "*") {
|
if (attr.name === "*") {
|
||||||
attr.dynamicAttribute = true;
|
attr.dynamicAttribute = true;
|
||||||
|
|
||||||
if (attr.targetProperty === null || attr.targetProperty === "") {
|
if (attr.targetProperty === undefined || attr.targetProperty === "") {
|
||||||
attr.targetProperty = null;
|
attr.targetProperty = null;
|
||||||
} else if (!attr.targetProperty) {
|
|
||||||
!this.isCoreTag() &&
|
|
||||||
complain(
|
|
||||||
'The default "targetProperty" for "@*" attribute definitions is changing from "*" to "null" (merged in with the rest of the input) in a future Marko release. In order to avoid an issue upgrading, please explicitly define the "targetProperty".',
|
|
||||||
{
|
|
||||||
location: this.filePath
|
|
||||||
}
|
|
||||||
);
|
|
||||||
attr.targetProperty = "*";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +101,7 @@ class Tag {
|
|||||||
}
|
}
|
||||||
forEachAttribute(callback, thisObj) {
|
forEachAttribute(callback, thisObj) {
|
||||||
for (var attrName in this.attributes) {
|
for (var attrName in this.attributes) {
|
||||||
if (this.attributes.hasOwnProperty(attrName)) {
|
if (hasOwnProperty.call(this.attributes, attrName)) {
|
||||||
callback.call(thisObj, this.attributes[attrName]);
|
callback.call(thisObj, this.attributes[attrName]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,57 +127,15 @@ class Tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasAttribute(attrName) {
|
hasAttribute(attrName) {
|
||||||
return this.attributes.hasOwnProperty(attrName);
|
return hasOwnProperty.call(this.attributes, attrName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DEPRECATED
|
|
||||||
*/
|
|
||||||
addNestedVariable(nestedVariable) {
|
|
||||||
complain("addNestedVariable is deprecated. Use tag parameters instead.", {
|
|
||||||
location: this.filePath
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!this.nestedVariables) {
|
|
||||||
this.nestedVariables = {
|
|
||||||
__noMerge: true,
|
|
||||||
vars: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
this.nestedVariables.vars.push(nestedVariable);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* DEPRECATED
|
|
||||||
*/
|
|
||||||
addImportedVariable(importedVariable) {
|
|
||||||
if (!this.importedVariables) {
|
|
||||||
this.importedVariables = {};
|
|
||||||
}
|
|
||||||
var key = importedVariable.targetProperty;
|
|
||||||
this.importedVariables[key] = importedVariable;
|
|
||||||
}
|
|
||||||
addTransformer(transformer) {
|
addTransformer(transformer) {
|
||||||
var key = transformer.path;
|
var key = transformer.path;
|
||||||
transformer.taglibId = this.taglibId;
|
transformer.taglibId = this.taglibId;
|
||||||
this.transformers[key] = transformer;
|
this.transformers[key] = transformer;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* DEPRECATED
|
|
||||||
*/
|
|
||||||
setBodyFunction(name, params) {
|
|
||||||
this.bodyFunction = {
|
|
||||||
__noMerge: true,
|
|
||||||
name: name,
|
|
||||||
params: params
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* DEPRECATED
|
|
||||||
*/
|
|
||||||
setBodyProperty(propertyName) {
|
|
||||||
this.bodyProperty = propertyName;
|
|
||||||
}
|
|
||||||
addNestedTag(nestedTag) {
|
addNestedTag(nestedTag) {
|
||||||
ok(nestedTag.name, '"nestedTag.name" is required');
|
ok(nestedTag.name, '"nestedTag.name" is required');
|
||||||
|
|
||||||
@ -266,41 +173,6 @@ class Tag {
|
|||||||
.forEach(callback, thisObj);
|
.forEach(callback, thisObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
getNodeFactory() {
|
|
||||||
var nodeFactory = this._nodeFactory;
|
|
||||||
if (nodeFactory !== undefined) {
|
|
||||||
return nodeFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
let codeGeneratorModulePath = this.codeGeneratorModulePath;
|
|
||||||
|
|
||||||
if (this.codeGeneratorModulePath) {
|
|
||||||
var loadedCodeGenerator = markoModules.require(
|
|
||||||
this.codeGeneratorModulePath
|
|
||||||
);
|
|
||||||
nodeFactory = function(elNode) {
|
|
||||||
elNode.setType(codeGeneratorModulePath);
|
|
||||||
elNode.setCodeGenerator(loadedCodeGenerator);
|
|
||||||
return elNode;
|
|
||||||
};
|
|
||||||
} else if (this.nodeFactoryPath) {
|
|
||||||
nodeFactory = markoModules.require(this.nodeFactoryPath);
|
|
||||||
if (typeof nodeFactory !== "function") {
|
|
||||||
throw new Error(
|
|
||||||
'Invalid node factory exported by module at path "' +
|
|
||||||
this.nodeFactoryPath +
|
|
||||||
'"'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (this.renderer || this.template || this.isNestedTag) {
|
|
||||||
nodeFactory = createCustomTagNodeFactory(this);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (this._nodeFactory = nodeFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -309,10 +181,6 @@ class Tag {
|
|||||||
this.taglibId = taglib ? taglib.id : null;
|
this.taglibId = taglib ? taglib.id : null;
|
||||||
this.taglibPath = taglib ? taglib.path : null;
|
this.taglibPath = taglib ? taglib.path : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
isCoreTag() {
|
|
||||||
return this.filePath && this.filePath.startsWith(coreTagsPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Tag;
|
module.exports = Tag;
|
||||||
|
|||||||
@ -4,10 +4,11 @@ var ok = require("assert").ok;
|
|||||||
var path = require("path");
|
var path = require("path");
|
||||||
var loaders = require("./loaders");
|
var loaders = require("./loaders");
|
||||||
var markoModules = require("../../compiler/modules");
|
var markoModules = require("../../compiler/modules");
|
||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
function handleImport(taglib, importedTaglib) {
|
function handleImport(taglib, importedTaglib) {
|
||||||
var importsLookup = taglib.importsLookup || (taglib.importsLookup = {});
|
var importsLookup = taglib.importsLookup || (taglib.importsLookup = {});
|
||||||
if (importsLookup.hasOwnProperty(importedTaglib.path)) {
|
if (hasOwnProperty.call(importsLookup, importedTaglib.path)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ var raptorRegexp = require("raptor-regexp");
|
|||||||
var propertyHandlers = require("property-handlers");
|
var propertyHandlers = require("property-handlers");
|
||||||
var types = require("./types");
|
var types = require("./types");
|
||||||
var createError = require("raptor-util/createError");
|
var createError = require("raptor-util/createError");
|
||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
class AttrLoader {
|
class AttrLoader {
|
||||||
constructor(attr, dependencyChain) {
|
constructor(attr, dependencyChain) {
|
||||||
@ -236,7 +237,7 @@ function loadAttributeFromProps(attrName, attrProps, dependencyChain) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadAttributeFromProps.isSupportedProperty = function(name) {
|
loadAttributeFromProps.isSupportedProperty = function(name) {
|
||||||
return AttrLoader.prototype.hasOwnProperty(name);
|
return hasOwnProperty.call(AttrLoader.prototype, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = loadAttributeFromProps;
|
module.exports = loadAttributeFromProps;
|
||||||
|
|||||||
@ -5,14 +5,11 @@ var propertyHandlers = require("property-handlers");
|
|||||||
var isObjectEmpty = require("raptor-util/isObjectEmpty");
|
var isObjectEmpty = require("raptor-util/isObjectEmpty");
|
||||||
var nodePath = require("path");
|
var nodePath = require("path");
|
||||||
var markoModules = require("../../compiler/modules"); // NOTE: different implementation for browser
|
var markoModules = require("../../compiler/modules"); // NOTE: different implementation for browser
|
||||||
var bodyFunctionRegExp = /^([A-Za-z_$][A-Za-z0-9_]*)(?:\(([^)]*)\))?$/;
|
|
||||||
var safeVarName = /^[A-Za-z_$][A-Za-z0-9_]*$/;
|
|
||||||
var forEachEntry = require("raptor-util/forEachEntry");
|
var forEachEntry = require("raptor-util/forEachEntry");
|
||||||
var markoCompiler = require("../../compiler");
|
|
||||||
var createError = require("raptor-util/createError");
|
var createError = require("raptor-util/createError");
|
||||||
var types = require("./types");
|
var types = require("./types");
|
||||||
var loaders = require("./loaders");
|
var loaders = require("./loaders");
|
||||||
var complain = require("complain");
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
function exists(path) {
|
function exists(path) {
|
||||||
try {
|
try {
|
||||||
@ -35,7 +32,7 @@ function hasAttributes(tagProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (var name in tagProps) {
|
for (var name in tagProps) {
|
||||||
if (tagProps.hasOwnProperty(name) && name.startsWith("@")) {
|
if (hasOwnProperty.call(tagProps, name) && name.startsWith("@")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,7 +71,7 @@ function addTransformer(tagLoader, value) {
|
|||||||
var properties =
|
var properties =
|
||||||
transformer.properties || (transformer.properties = {});
|
transformer.properties || (transformer.properties = {});
|
||||||
for (var k in value) {
|
for (var k in value) {
|
||||||
if (value.hasOwnProperty(k)) {
|
if (hasOwnProperty.call(value, k)) {
|
||||||
properties[k] = value[k];
|
properties[k] = value[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +200,7 @@ class TagLoader {
|
|||||||
|
|
||||||
if (value != null && typeof value === "object") {
|
if (value != null && typeof value === "object") {
|
||||||
for (k in value) {
|
for (k in value) {
|
||||||
if (value.hasOwnProperty(k)) {
|
if (hasOwnProperty.call(value, k)) {
|
||||||
if (k.startsWith("@") || k.startsWith("<")) {
|
if (k.startsWith("@") || k.startsWith("<")) {
|
||||||
// Move over all of the attributes and nested tags
|
// Move over all of the attributes and nested tags
|
||||||
// to the tag definition.
|
// to the tag definition.
|
||||||
@ -421,18 +418,6 @@ class TagLoader {
|
|||||||
tag.nodeFactoryPath = path;
|
tag.nodeFactoryPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DEPRECATED: use parse-options.preserveWhitespace
|
|
||||||
* If the "preserve-whitespace" property is set to true then
|
|
||||||
* all whitespace nested below the custom tag in a template
|
|
||||||
* will be stripped instead of going through the normal whitespace
|
|
||||||
* removal rules.
|
|
||||||
*/
|
|
||||||
preserveWhitespace(value) {
|
|
||||||
var tag = this.tag;
|
|
||||||
tag.preserveWhitespace = !!value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a custom tag has an associated transformer then the transformer
|
* If a custom tag has an associated transformer then the transformer
|
||||||
* will be called on the compile-time Node. The transformer can manipulate
|
* will be called on the compile-time Node. The transformer can manipulate
|
||||||
@ -461,128 +446,6 @@ class TagLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DEPRECATED: use tag parameters
|
|
||||||
* The "var" property is used to declared nested variables that get
|
|
||||||
* added as JavaScript variables at compile time.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* "var": "myScopedVariable",
|
|
||||||
*
|
|
||||||
* "var": {
|
|
||||||
* "name": "myScopedVariable"
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* "var": {
|
|
||||||
* "name-from-attribute": "var"
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
var(value) {
|
|
||||||
complain("var is deprecated. Use tag parameters instead.", {
|
|
||||||
location: this.filePath
|
|
||||||
});
|
|
||||||
this._handleVar(value, this.dependencyChain.append("var"));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* DEPRECATED: use tag parameters
|
|
||||||
* The "vars" property is equivalent to the "var" property
|
|
||||||
* except that it expects an array of nested variables.
|
|
||||||
*/
|
|
||||||
vars(value) {
|
|
||||||
complain("vars is deprecated. Use tag parameters instead.", {
|
|
||||||
location: this.filePath
|
|
||||||
});
|
|
||||||
if (value) {
|
|
||||||
value.forEach((v, i) => {
|
|
||||||
this._handleVar(v, this.dependencyChain.append("vars[" + i + "]"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* DEPRECATED
|
|
||||||
* The "body-function" property" allows the nested body content to be mapped
|
|
||||||
* to a function at compile time. The body function gets mapped to a property
|
|
||||||
* of the tag renderer at render time. The body function can have any number
|
|
||||||
* of parameters.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* - "body-function": "_handleBody(param1, param2, param3)"
|
|
||||||
*/
|
|
||||||
bodyFunction(value) {
|
|
||||||
var tag = this.tag;
|
|
||||||
var parts = bodyFunctionRegExp.exec(value);
|
|
||||||
if (!parts) {
|
|
||||||
throw new Error(
|
|
||||||
'Invalid value of "' +
|
|
||||||
value +
|
|
||||||
'" for "body-function". Expected value to be of the following form: <function-name>([param1, param2, ...])'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
var functionName = parts[1];
|
|
||||||
var params = parts[2];
|
|
||||||
if (params) {
|
|
||||||
params = params.trim().split(/\s*,\s*/);
|
|
||||||
for (var i = 0; i < params.length; i++) {
|
|
||||||
if (params[i].length === 0) {
|
|
||||||
throw new Error(
|
|
||||||
'Invalid parameters for body-function with value of "' + value + '"'
|
|
||||||
);
|
|
||||||
} else if (!safeVarName.test(params[i])) {
|
|
||||||
throw new Error(
|
|
||||||
'Invalid parameter name of "' +
|
|
||||||
params[i] +
|
|
||||||
'" for body-function with value of "' +
|
|
||||||
value +
|
|
||||||
'"'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
params = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
tag.setBodyFunction(functionName, params);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* DEPRECATED: use transformer to add additional attributes
|
|
||||||
* The "import-var" property can be used to add a property to the
|
|
||||||
* input object of the tag renderer whose value is determined by
|
|
||||||
* a JavaScript expression.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* "import-var": {
|
|
||||||
* "myTargetProperty": "data.myCompileTimeJavaScriptExpression",
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
importVar(value) {
|
|
||||||
var tag = this.tag;
|
|
||||||
forEachEntry(value, (varName, varValue) => {
|
|
||||||
var importedVar = {
|
|
||||||
targetProperty: varName
|
|
||||||
};
|
|
||||||
|
|
||||||
var expression = varValue;
|
|
||||||
|
|
||||||
if (!expression) {
|
|
||||||
expression = varName;
|
|
||||||
} else if (typeof expression === "object") {
|
|
||||||
expression = expression.expression;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!expression) {
|
|
||||||
throw new Error(
|
|
||||||
'Invalid "import-var": ' + require("util").inspect(varValue)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
importedVar.expression = markoCompiler.builder.parseExpression(
|
|
||||||
expression
|
|
||||||
);
|
|
||||||
tag.addImportedVariable(importedVar);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* The tag type.
|
* The tag type.
|
||||||
*/
|
*/
|
||||||
@ -630,45 +493,11 @@ class TagLoader {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* DEPRECATED
|
|
||||||
*/
|
|
||||||
escapeXmlBody(value) {
|
|
||||||
if (value === false) {
|
|
||||||
this.tag.escapeXmlBody = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DEPRECATED: use parse-options.state instead
|
|
||||||
* Sends the body content type. This is used to control how the body
|
|
||||||
* content is parsed.
|
|
||||||
*/
|
|
||||||
body(value) {
|
|
||||||
if (
|
|
||||||
value === "static-text" ||
|
|
||||||
value === "parsed-text" ||
|
|
||||||
value === "html"
|
|
||||||
) {
|
|
||||||
this.tag.body = value;
|
|
||||||
} else {
|
|
||||||
throw new Error(
|
|
||||||
'Invalid value for "body". Allowed: "static-text", "parsed-text" or "html"'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
openTagOnly(value) {
|
openTagOnly(value) {
|
||||||
this.tag.openTagOnly = value;
|
this.tag.openTagOnly = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DEPRECATED
|
|
||||||
*/
|
|
||||||
noOutput(value) {
|
|
||||||
this.tag.noOutput = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The description of the tag. Only used for documentation.
|
* The description of the tag. Only used for documentation.
|
||||||
*/
|
*/
|
||||||
@ -688,13 +517,6 @@ class TagLoader {
|
|||||||
this.tag.deprecated = value;
|
this.tag.deprecated = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* DEPRECATED: use parse-options.ignoreAttributes instead
|
|
||||||
*/
|
|
||||||
parseAttributes(value) {
|
|
||||||
this.tag.parseAttributes = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
attributeGroups(value) {
|
attributeGroups(value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return;
|
return;
|
||||||
@ -719,7 +541,7 @@ class TagLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isSupportedProperty(name) {
|
function isSupportedProperty(name) {
|
||||||
return TagLoader.prototype.hasOwnProperty(name);
|
return hasOwnProperty.call(TagLoader.prototype, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadTagFromProps(tag, tagProps, dependencyChain) {
|
function loadTagFromProps(tag, tagProps, dependencyChain) {
|
||||||
|
|||||||
@ -11,6 +11,7 @@ var resolveFrom = typeof window === "undefined" && require("resolve-from"); // N
|
|||||||
var DependencyChain = require("./DependencyChain");
|
var DependencyChain = require("./DependencyChain");
|
||||||
var createError = require("raptor-util/createError");
|
var createError = require("raptor-util/createError");
|
||||||
var loaders = require("./loaders");
|
var loaders = require("./loaders");
|
||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
function exists(path) {
|
function exists(path) {
|
||||||
try {
|
try {
|
||||||
@ -213,7 +214,7 @@ class TaglibLoader {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
for (var tagName in tags) {
|
for (var tagName in tags) {
|
||||||
if (tags.hasOwnProperty(tagName)) {
|
if (hasOwnProperty.call(tags, tagName)) {
|
||||||
this._handleTag(
|
this._handleTag(
|
||||||
tagName,
|
tagName,
|
||||||
tags[tagName],
|
tags[tagName],
|
||||||
|
|||||||
@ -2,6 +2,4 @@ exports.Taglib = require("./Taglib");
|
|||||||
exports.Tag = require("./Tag");
|
exports.Tag = require("./Tag");
|
||||||
exports.Attribute = require("./Attribute");
|
exports.Attribute = require("./Attribute");
|
||||||
exports.Property = require("./Property");
|
exports.Property = require("./Property");
|
||||||
exports.NestedVariable = require("./NestedVariable"); // DEPRECATED
|
|
||||||
exports.ImportedVariable = require("./ImportedVariable"); // DEPRECATED
|
|
||||||
exports.Transformer = require("./Transformer");
|
exports.Transformer = require("./Transformer");
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
var ok = require("assert").ok;
|
var ok = require("assert").ok;
|
||||||
var taglibTypes = require("../taglib-loader/types");
|
var taglibTypes = require("../taglib-loader/types");
|
||||||
var Text = require("../../compiler/ast/Text");
|
|
||||||
var extend = require("raptor-util/extend");
|
var extend = require("raptor-util/extend");
|
||||||
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
function transformerComparator(a, b) {
|
function transformerComparator(a, b) {
|
||||||
a = a.priority;
|
a = a.priority;
|
||||||
@ -28,7 +28,7 @@ function TAG_COMPARATOR(a, b) {
|
|||||||
|
|
||||||
function merge(target, source) {
|
function merge(target, source) {
|
||||||
for (var k in source) {
|
for (var k in source) {
|
||||||
if (source.hasOwnProperty(k)) {
|
if (hasOwnProperty.call(source, k)) {
|
||||||
if (
|
if (
|
||||||
target[k] &&
|
target[k] &&
|
||||||
typeof target[k] === "object" &&
|
typeof target[k] === "object" &&
|
||||||
@ -85,7 +85,7 @@ class TaglibLookup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasTaglib(taglib) {
|
hasTaglib(taglib) {
|
||||||
return this.taglibsById.hasOwnProperty(taglib.id);
|
return hasOwnProperty.call(this.taglibsById, taglib.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
_mergeNestedTags(taglib) {
|
_mergeNestedTags(taglib) {
|
||||||
@ -120,7 +120,7 @@ class TaglibLookup {
|
|||||||
ok(taglib, '"taglib" is required');
|
ok(taglib, '"taglib" is required');
|
||||||
ok(taglib.id, '"taglib.id" expected');
|
ok(taglib.id, '"taglib.id" expected');
|
||||||
|
|
||||||
if (this.taglibsById.hasOwnProperty(taglib.id)) {
|
if (hasOwnProperty.call(this.taglibsById, taglib.id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ class TaglibLookup {
|
|||||||
var tags = this.merged.tags;
|
var tags = this.merged.tags;
|
||||||
if (tags) {
|
if (tags) {
|
||||||
for (var tagName in tags) {
|
for (var tagName in tags) {
|
||||||
if (tags.hasOwnProperty(tagName)) {
|
if (hasOwnProperty.call(tags, tagName)) {
|
||||||
var tag = tags[tagName];
|
var tag = tags[tagName];
|
||||||
var result = callback(tag);
|
var result = callback(tag);
|
||||||
if (result === false) {
|
if (result === false) {
|
||||||
@ -199,7 +199,7 @@ class TaglibLookup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (var attrName in attributes) {
|
for (var attrName in attributes) {
|
||||||
if (attributes.hasOwnProperty(attrName)) {
|
if (hasOwnProperty.call(attributes, attrName)) {
|
||||||
handleAttr(attributes[attrName], tag);
|
handleAttr(attributes[attrName], tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,17 +380,6 @@ class TaglibLookup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forEachNodeTransformer(node, callback, thisObj) {
|
|
||||||
/*
|
|
||||||
* Based on the type of node we have to choose how to transform it
|
|
||||||
*/
|
|
||||||
if (node.tagName || node.tagNameExpression) {
|
|
||||||
this.forEachTagTransformer(node, callback, thisObj);
|
|
||||||
} else if (node instanceof Text) {
|
|
||||||
this.forEachTextTransformer(callback, thisObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
forEachTagTransformer(element, callback, thisObj) {
|
forEachTagTransformer(element, callback, thisObj) {
|
||||||
if (typeof element === "string") {
|
if (typeof element === "string") {
|
||||||
element = {
|
element = {
|
||||||
@ -449,7 +438,7 @@ class TaglibLookup {
|
|||||||
var inputFilesSet = {};
|
var inputFilesSet = {};
|
||||||
|
|
||||||
for (var taglibId in this.taglibsById) {
|
for (var taglibId in this.taglibsById) {
|
||||||
if (this.taglibsById.hasOwnProperty(taglibId)) {
|
if (hasOwnProperty.call(this.taglibsById, taglibId)) {
|
||||||
var taglibInputFiles = this.taglibsById[taglibId].getInputFiles();
|
var taglibInputFiles = this.taglibsById[taglibId].getInputFiles();
|
||||||
var len = taglibInputFiles.length;
|
var len = taglibInputFiles.length;
|
||||||
if (len) {
|
if (len) {
|
||||||
|
|||||||
@ -54,6 +54,7 @@ BrowserHelpers.prototype = {
|
|||||||
mount: function(templatePath, input) {
|
mount: function(templatePath, input) {
|
||||||
var $global = input && input.$global;
|
var $global = input && input.$global;
|
||||||
var template = require(templatePath);
|
var template = require(templatePath);
|
||||||
|
template = template.default || template;
|
||||||
var renderResult = template.renderSync(input).appendTo(this.targetEl);
|
var renderResult = template.renderSync(input).appendTo(this.targetEl);
|
||||||
var instance;
|
var instance;
|
||||||
|
|
||||||
|
|||||||
@ -1,23 +1,25 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const getComponents = (module.exports = (template, components) => {
|
const getComponents = (module.exports = (template, components) => {
|
||||||
var meta = template.meta;
|
const meta = template.meta;
|
||||||
components = components || {};
|
components = components || {};
|
||||||
if (meta) {
|
if (meta) {
|
||||||
if (!components[meta.id]) {
|
if (!components[meta.id]) {
|
||||||
if (meta.id && meta.component) {
|
const dir = path.dirname(template.path);
|
||||||
components[meta.id] = path.resolve(
|
components[meta.id] =
|
||||||
path.dirname(template.path),
|
meta.component && /-browser/.test(meta.component)
|
||||||
meta.component
|
? path.resolve(dir, meta.component)
|
||||||
);
|
: template.path;
|
||||||
}
|
|
||||||
if (meta.tags) {
|
if (meta.tags) {
|
||||||
|
const dir = path.dirname(template.path);
|
||||||
meta.tags.forEach(tagRelativePath => {
|
meta.tags.forEach(tagRelativePath => {
|
||||||
var tagPath =
|
var tagPath =
|
||||||
"." === tagRelativePath[0]
|
"." === tagRelativePath[0]
|
||||||
? path.resolve(path.dirname(template.path), tagRelativePath)
|
? path.resolve(dir, tagRelativePath)
|
||||||
: tagRelativePath;
|
: tagRelativePath;
|
||||||
var tagTemplate = require(tagPath);
|
var tagTemplate = require(tagPath);
|
||||||
|
tagTemplate = tagTemplate.default || tagTemplate;
|
||||||
components = getComponents(tagTemplate, components);
|
components = getComponents(tagTemplate, components);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const jQuery = require("jquery");
|
|
||||||
const createBrowser = require("jsdom-context-require");
|
const createBrowser = require("jsdom-context-require");
|
||||||
const compiler = require("../../compiler");
|
const compiler = require("../../compiler");
|
||||||
const globals = [
|
const globals = [
|
||||||
@ -30,7 +29,6 @@ module.exports = function(dir, html, options) {
|
|||||||
beforeParse(window, browser) {
|
beforeParse(window, browser) {
|
||||||
window.global = window;
|
window.global = window;
|
||||||
window.alert = () => {};
|
window.alert = () => {};
|
||||||
jQuery(window);
|
|
||||||
browser.require("complain").log = (...args) =>
|
browser.require("complain").log = (...args) =>
|
||||||
require("complain").log(...args);
|
require("complain").log(...args);
|
||||||
globals.forEach(function(k) {
|
globals.forEach(function(k) {
|
||||||
|
|||||||
@ -11,21 +11,22 @@ var markoDir = isDebug
|
|||||||
? nodePath.join(rootDir, "src")
|
? nodePath.join(rootDir, "src")
|
||||||
: nodePath.join(rootDir, "dist");
|
: nodePath.join(rootDir, "dist");
|
||||||
|
|
||||||
var markoInstalledDir = nodePath.join(rootDir, "node_modules/marko");
|
try {
|
||||||
if (fs.existsSync(markoInstalledDir)) {
|
var markoInstalledDir = nodePath.dirname(require.resolve("marko"));
|
||||||
fs.renameSync(
|
if (fs.existsSync(markoInstalledDir)) {
|
||||||
markoInstalledDir,
|
fs.renameSync(
|
||||||
nodePath.join(rootDir, "node_modules/~marko")
|
markoInstalledDir,
|
||||||
);
|
markoInstalledDir.replace("node_modules/marko", "node_modules/~marko")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// ignore error
|
||||||
}
|
}
|
||||||
|
|
||||||
Module._resolveFilename = function(request, parent, isMain) {
|
Module._resolveFilename = function(request, parent, isMain) {
|
||||||
if (request.charAt(0) !== ".") {
|
if (request.charAt(0) !== "." && parent.filename.startsWith(rootDir)) {
|
||||||
if (
|
if (
|
||||||
request === "marko/components" ||
|
request === "marko/components" ||
|
||||||
request === "marko/jquery" ||
|
|
||||||
request === "marko/legacy-components" ||
|
|
||||||
request === "marko/ready" ||
|
|
||||||
request === "marko/env" ||
|
request === "marko/env" ||
|
||||||
request.startsWith("marko/dist/") ||
|
request.startsWith("marko/dist/") ||
|
||||||
request.startsWith("marko/src/") ||
|
request.startsWith("marko/src/") ||
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
require("./patch-module");
|
require("./patch-module");
|
||||||
require("../../node-require").install({
|
require("../../node-require").install({
|
||||||
compilerOptions: { writeToDisk: false },
|
|
||||||
extensions: [".marko", ".html"]
|
extensions: [".marko", ".html"]
|
||||||
});
|
});
|
||||||
require("it-fails");
|
require("it-fails");
|
||||||
|
|||||||
@ -1,27 +1 @@
|
|||||||
"use strict";
|
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;var _renderer = _interopRequireDefault(require("marko/src/runtime/components/renderer"));var _vdom = require("marko/src/runtime/vdom");var _registryBrowser = require("marko/src/runtime/components/registry-browser");var _defineComponent = _interopRequireDefault(require("marko/src/runtime/components/defineComponent"));const _marko_template = (0, _vdom.t)(__filename);var _default = _marko_template;exports.default = _default;const _marko_componentType = (0, _registryBrowser.r)("R6GeK_TQ", () => _marko_template),_marko_component = {};_marko_template._ = (0, _renderer.default)(function (input, out, _component, component, state) {out.t("Hello ");out.t(input.name);out.t("!");}, { ___type: _marko_componentType, ___implicit: true }, _marko_component);_marko_template.Component = (0, _defineComponent.default)(_marko_component, _marko_template._);
|
||||||
|
|
||||||
var marko_template = module.exports = require("marko/src/vdom").t(),
|
|
||||||
components_registry_browser = require("marko/src/runtime/components/registry-browser"),
|
|
||||||
marko_registerComponent = components_registry_browser.r,
|
|
||||||
marko_componentType = marko_registerComponent("/marko-test$1.0.0/api-compiler/fixtures/compileFileForBrowser-callback.js/template.marko", function() {
|
|
||||||
return module.exports;
|
|
||||||
}),
|
|
||||||
marko_renderer = require("marko/src/runtime/components/renderer"),
|
|
||||||
marko_defineComponent = require("marko/src/runtime/components/defineComponent");
|
|
||||||
|
|
||||||
function render(input, out, __component, component, state) {
|
|
||||||
var data = input;
|
|
||||||
|
|
||||||
out.t("Hello ");
|
|
||||||
|
|
||||||
out.t(data.name);
|
|
||||||
|
|
||||||
out.t("!");
|
|
||||||
}
|
|
||||||
|
|
||||||
marko_template._ = marko_renderer(render, {
|
|
||||||
___implicit: true,
|
|
||||||
___type: marko_componentType
|
|
||||||
});
|
|
||||||
|
|
||||||
marko_template.Component = marko_defineComponent({}, marko_template._);
|
|
||||||
@ -1,27 +1 @@
|
|||||||
"use strict";
|
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;var _renderer = _interopRequireDefault(require("marko/src/runtime/components/renderer"));var _vdom = require("marko/src/runtime/vdom");var _registryBrowser = require("marko/src/runtime/components/registry-browser");var _defineComponent = _interopRequireDefault(require("marko/src/runtime/components/defineComponent"));const _marko_template = (0, _vdom.t)(__filename);var _default = _marko_template;exports.default = _default;const _marko_componentType = (0, _registryBrowser.r)("73lE6A3Z", () => _marko_template),_marko_component = {};_marko_template._ = (0, _renderer.default)(function (input, out, _component, component, state) {out.t("Hello ");out.t(input.name);out.t("!");}, { ___type: _marko_componentType, ___implicit: true }, _marko_component);_marko_template.Component = (0, _defineComponent.default)(_marko_component, _marko_template._);
|
||||||
|
|
||||||
var marko_template = module.exports = require("marko/src/vdom").t(),
|
|
||||||
components_registry_browser = require("marko/src/runtime/components/registry-browser"),
|
|
||||||
marko_registerComponent = components_registry_browser.r,
|
|
||||||
marko_componentType = marko_registerComponent("/marko-test$1.0.0/api-compiler/fixtures/compileFileForBrowser.js/template.marko", function() {
|
|
||||||
return module.exports;
|
|
||||||
}),
|
|
||||||
marko_renderer = require("marko/src/runtime/components/renderer"),
|
|
||||||
marko_defineComponent = require("marko/src/runtime/components/defineComponent");
|
|
||||||
|
|
||||||
function render(input, out, __component, component, state) {
|
|
||||||
var data = input;
|
|
||||||
|
|
||||||
out.t("Hello ");
|
|
||||||
|
|
||||||
out.t(data.name);
|
|
||||||
|
|
||||||
out.t("!");
|
|
||||||
}
|
|
||||||
|
|
||||||
marko_template._ = marko_renderer(render, {
|
|
||||||
___implicit: true,
|
|
||||||
___type: marko_componentType
|
|
||||||
});
|
|
||||||
|
|
||||||
marko_template.Component = marko_defineComponent({}, marko_template._);
|
|
||||||
@ -1,27 +1 @@
|
|||||||
"use strict";
|
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;var _renderer = _interopRequireDefault(require("marko/src/runtime/components/renderer"));var _vdom = require("marko/src/runtime/vdom");var _registryBrowser = require("marko/src/runtime/components/registry-browser");var _defineComponent = _interopRequireDefault(require("marko/src/runtime/components/defineComponent"));const _marko_template = (0, _vdom.t)(__filename);var _default = _marko_template;exports.default = _default;const _marko_componentType = (0, _registryBrowser.r)("UjcD7_Jz", () => _marko_template),_marko_component = {};_marko_template._ = (0, _renderer.default)(function (input, out, _component, component, state) {out.t("Hello ");out.t(input.name);out.t("!");}, { ___type: _marko_componentType, ___implicit: true }, _marko_component);_marko_template.Component = (0, _defineComponent.default)(_marko_component, _marko_template._);
|
||||||
|
|
||||||
var marko_template = module.exports = require("marko/src/vdom").t(),
|
|
||||||
components_registry_browser = require("marko/src/runtime/components/registry-browser"),
|
|
||||||
marko_registerComponent = components_registry_browser.r,
|
|
||||||
marko_componentType = marko_registerComponent("/marko-test$1.0.0/api-compiler/fixtures/compileForBrowser-callback.js/template.marko", function() {
|
|
||||||
return module.exports;
|
|
||||||
}),
|
|
||||||
marko_renderer = require("marko/src/runtime/components/renderer"),
|
|
||||||
marko_defineComponent = require("marko/src/runtime/components/defineComponent");
|
|
||||||
|
|
||||||
function render(input, out, __component, component, state) {
|
|
||||||
var data = input;
|
|
||||||
|
|
||||||
out.t("Hello ");
|
|
||||||
|
|
||||||
out.t(data.name);
|
|
||||||
|
|
||||||
out.t("!");
|
|
||||||
}
|
|
||||||
|
|
||||||
marko_template._ = marko_renderer(render, {
|
|
||||||
___implicit: true,
|
|
||||||
___type: marko_componentType
|
|
||||||
});
|
|
||||||
|
|
||||||
marko_template.Component = marko_defineComponent({}, marko_template._);
|
|
||||||
@ -3,7 +3,7 @@ var path = require("path");
|
|||||||
var markoVersion = require("../../../../package.json").version;
|
var markoVersion = require("../../../../package.json").version;
|
||||||
|
|
||||||
function getMarkoVersionComment() {
|
function getMarkoVersionComment() {
|
||||||
return "// Compiled using marko@" + markoVersion + " - DO NOT EDIT\n";
|
return "Compiled using marko@" + markoVersion + " - DO NOT EDIT";
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.check = function(marko, markoCompiler, expect, helpers, done) {
|
exports.check = function(marko, markoCompiler, expect, helpers, done) {
|
||||||
|
|||||||
@ -1,27 +1 @@
|
|||||||
"use strict";
|
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;var _renderer = _interopRequireDefault(require("marko/src/runtime/components/renderer"));var _vdom = require("marko/src/runtime/vdom");var _registryBrowser = require("marko/src/runtime/components/registry-browser");var _defineComponent = _interopRequireDefault(require("marko/src/runtime/components/defineComponent"));const _marko_template = (0, _vdom.t)(__filename);var _default = _marko_template;exports.default = _default;const _marko_componentType = (0, _registryBrowser.r)("E0Fkd6Tw", () => _marko_template),_marko_component = {};_marko_template._ = (0, _renderer.default)(function (input, out, _component, component, state) {out.t("Hello ");out.t(input.name);out.t("!");}, { ___type: _marko_componentType, ___implicit: true }, _marko_component);_marko_template.Component = (0, _defineComponent.default)(_marko_component, _marko_template._);
|
||||||
|
|
||||||
var marko_template = module.exports = require("marko/src/vdom").t(),
|
|
||||||
components_registry_browser = require("marko/src/runtime/components/registry-browser"),
|
|
||||||
marko_registerComponent = components_registry_browser.r,
|
|
||||||
marko_componentType = marko_registerComponent("/marko-test$1.0.0/api-compiler/fixtures/compileForBrowser.js/template.marko", function() {
|
|
||||||
return module.exports;
|
|
||||||
}),
|
|
||||||
marko_renderer = require("marko/src/runtime/components/renderer"),
|
|
||||||
marko_defineComponent = require("marko/src/runtime/components/defineComponent");
|
|
||||||
|
|
||||||
function render(input, out, __component, component, state) {
|
|
||||||
var data = input;
|
|
||||||
|
|
||||||
out.t("Hello ");
|
|
||||||
|
|
||||||
out.t(data.name);
|
|
||||||
|
|
||||||
out.t("!");
|
|
||||||
}
|
|
||||||
|
|
||||||
marko_template._ = marko_renderer(render, {
|
|
||||||
___implicit: true,
|
|
||||||
___type: marko_componentType
|
|
||||||
});
|
|
||||||
|
|
||||||
marko_template.Component = marko_defineComponent({}, marko_template._);
|
|
||||||
@ -1,19 +1,17 @@
|
|||||||
exports.check = function(marko, markoCompiler, expect, helpers, done) {
|
exports.check = function(marko, markoCompiler, expect, helpers, done) {
|
||||||
var compiler = require("marko/compiler");
|
var compiler = require("marko/compiler");
|
||||||
compiler.configure(); // Use defaults
|
compiler.configure(); // Use defaults
|
||||||
expect(compiler.config.writeToDisk).to.equal(true);
|
|
||||||
expect(compiler.config.preserveWhitespace).to.equal(false);
|
|
||||||
expect(compiler.config.writeVersionComment).to.equal(true);
|
expect(compiler.config.writeVersionComment).to.equal(true);
|
||||||
expect(compiler.config.ignoreUnrecognizedTags).to.equal(false);
|
expect(compiler.config.ignoreUnrecognizedTags).to.equal(false);
|
||||||
|
|
||||||
compiler.configure({
|
compiler.configure({
|
||||||
preserveWhitespace: true
|
ignoreUnrecognizedTags: true
|
||||||
});
|
});
|
||||||
expect(compiler.config.writeToDisk).to.equal(true);
|
expect(compiler.config.writeVersionComment).to.equal(true);
|
||||||
expect(compiler.config.preserveWhitespace).to.equal(true);
|
expect(compiler.config.ignoreUnrecognizedTags).to.equal(true);
|
||||||
|
|
||||||
compiler.configure(); // Use defaults
|
compiler.configure(); // Use defaults
|
||||||
expect(compiler.config.writeToDisk).to.equal(true);
|
expect(compiler.config.writeVersionComment).to.equal(true);
|
||||||
expect(compiler.config.preserveWhitespace).to.equal(false);
|
expect(compiler.config.ignoreUnrecognizedTags).to.equal(false);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,7 +6,7 @@ var chai = require("chai");
|
|||||||
chai.config.includeStack = true;
|
chai.config.includeStack = true;
|
||||||
var expect = require("chai").expect;
|
var expect = require("chai").expect;
|
||||||
require("../../compiler");
|
require("../../compiler");
|
||||||
var autotest = require("../autotest");
|
var autotest = require("mocha-autotest").default;
|
||||||
var marko = require("../../");
|
var marko = require("../../");
|
||||||
var markoCompiler = require("../../compiler");
|
var markoCompiler = require("../../compiler");
|
||||||
|
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
<% throw new Error('Test'); %>
|
$ throw new Error('Test');
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<missing-tag></missing-tag>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
Hello Frank!
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<missing-tag/>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
Hello Frank!
|
||||||
@ -1,5 +1,4 @@
|
|||||||
var nodePath = require("path");
|
var nodePath = require("path");
|
||||||
var fs = require("fs");
|
|
||||||
|
|
||||||
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
||||||
var template;
|
var template;
|
||||||
@ -8,28 +7,22 @@ exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
|||||||
// Make sure calling load with templatePath:String, templateSrc:String arguments works
|
// Make sure calling load with templatePath:String, templateSrc:String arguments works
|
||||||
templatePath = nodePath.join(__dirname, "dummy.marko");
|
templatePath = nodePath.join(__dirname, "dummy.marko");
|
||||||
template = marko.load(templatePath, "-- Hello $!{data.name}!");
|
template = marko.load(templatePath, "-- Hello $!{data.name}!");
|
||||||
snapshot(template.renderSync({ name: "Frank" }).toString());
|
snapshot(template.renderSync({ name: "Frank" }).toString(), {
|
||||||
|
name: "no-options"
|
||||||
|
});
|
||||||
|
|
||||||
// Make sure calling load with templatePath:String, templateSrc:String, options:Object arguments works
|
// Make sure calling load with templatePath:String, templateSrc:String, options:Object arguments works
|
||||||
templatePath = nodePath.join(__dirname, "dummy.marko");
|
templatePath = nodePath.join(__dirname, "dummy.marko");
|
||||||
template = marko.load(templatePath, "-- Hello $!{data.name}!", {});
|
template = marko.load(templatePath, "-- Hello $!{data.name}!", {});
|
||||||
snapshot(template.renderSync({ name: "Frank" }).toString());
|
snapshot(template.renderSync({ name: "Frank" }).toString(), {
|
||||||
|
name: "empty-options"
|
||||||
|
});
|
||||||
|
|
||||||
// Make sure calling load with templatePath:String, options:Object arguments works
|
// Make sure calling load with templatePath:String, options:Object arguments works
|
||||||
delete markoCompiler.defaultOptions.writeToDisk;
|
templatePath = nodePath.join(__dirname, "invalid-template.marko");
|
||||||
|
|
||||||
templatePath = nodePath.join(__dirname, "template.marko");
|
template = marko.load(templatePath, { ignoreUnrecognizedTags: true });
|
||||||
var compiledPath = nodePath.join(__dirname, "template.marko.js");
|
|
||||||
|
|
||||||
try {
|
|
||||||
fs.unlinkSync(compiledPath);
|
|
||||||
} catch (e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
template = marko.load(templatePath, { writeToDisk: false });
|
|
||||||
expect(fs.existsSync(compiledPath)).to.equal(false);
|
|
||||||
expect(template.render).to.be.a("function");
|
expect(template.render).to.be.a("function");
|
||||||
snapshot(template.renderSync({ name: "Frank" }).toString());
|
snapshot(template.renderSync({}).toString(), { name: "custom-options" });
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,7 @@ exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
|||||||
output += data;
|
output += data;
|
||||||
});
|
});
|
||||||
|
|
||||||
var runtimeHtml = require("marko/src/html");
|
var runtimeHtml = require("marko/runtime/html");
|
||||||
|
|
||||||
var out = runtimeHtml.createWriter(stream);
|
var out = runtimeHtml.createWriter(stream);
|
||||||
out
|
out
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
var nodePath = require("path");
|
var nodePath = require("path");
|
||||||
|
|
||||||
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
||||||
var runtimeHtml = require("marko/html");
|
var runtimeHtml = require("marko/runtime/html");
|
||||||
|
|
||||||
var out = runtimeHtml.createWriter();
|
var out = runtimeHtml.createWriter();
|
||||||
out
|
out
|
||||||
|
|||||||
@ -6,7 +6,7 @@ exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
|||||||
try {
|
try {
|
||||||
var templatePath = nodePath.join(__dirname, "template.marko");
|
var templatePath = nodePath.join(__dirname, "template.marko");
|
||||||
var compiledPath = nodePath.join(__dirname, "template.marko.js");
|
var compiledPath = nodePath.join(__dirname, "template.marko.js");
|
||||||
var template = require(templatePath);
|
var template = require(templatePath).default;
|
||||||
expect(fs.existsSync(compiledPath)).to.equal(false);
|
expect(fs.existsSync(compiledPath)).to.equal(false);
|
||||||
expect(template.render).to.be.a("function");
|
expect(template.render).to.be.a("function");
|
||||||
snapshot(template.renderSync({ name: "Frank" }).toString());
|
snapshot(template.renderSync({ name: "Frank" }).toString());
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
||||||
var template = require("./template.marko");
|
var template = require("./template.marko").default;
|
||||||
var data = {
|
var data = {
|
||||||
name: "John"
|
name: "John"
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,9 +4,7 @@ exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
|||||||
// Load the JS file to ensure the hello.marko.js file is created
|
// Load the JS file to ensure the hello.marko.js file is created
|
||||||
marko.load(nodePath.join(__dirname, "template.marko"));
|
marko.load(nodePath.join(__dirname, "template.marko"));
|
||||||
|
|
||||||
var templateModule = require(nodePath.join(__dirname, "template.marko.js"));
|
var template = require(nodePath.join(__dirname, "template.marko")).default;
|
||||||
|
|
||||||
var template = marko.load(templateModule);
|
|
||||||
template.render(
|
template.render(
|
||||||
{
|
{
|
||||||
name: "John"
|
name: "John"
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
<missing-tag/>
|
||||||
@ -1,89 +1,47 @@
|
|||||||
var expect = require("chai").expect;
|
var expect = require("chai").expect;
|
||||||
var fs = require("fs");
|
|
||||||
var requireHook = require("../../../../node-require");
|
var requireHook = require("../../../../node-require");
|
||||||
|
|
||||||
function compileAndCheck(path, shouldWriteToDisk) {
|
function compileAndCheck(path, shouldHaveErrored) {
|
||||||
var resolved = require.resolve(path);
|
var resolved = require.resolve(path);
|
||||||
var compiledFile = resolved + ".js";
|
var err;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(compiledFile);
|
require(resolved);
|
||||||
} catch (e) {
|
} catch (_e) {
|
||||||
/* ignore error */
|
err = _e;
|
||||||
}
|
}
|
||||||
|
|
||||||
require(resolved);
|
if (shouldHaveErrored) {
|
||||||
|
expect(err).is.an.instanceOf(Error);
|
||||||
expect(fs.existsSync(compiledFile)).to.equal(shouldWriteToDisk);
|
} else {
|
||||||
|
expect(err).to.equal(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.check = function(marko, markoCompiler, expect, helpers, done) {
|
exports.check = function(marko, markoCompiler, expect, helpers, done) {
|
||||||
try {
|
try {
|
||||||
requireHook.install({
|
requireHook.install({
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
writeToDisk: true,
|
ignoreUnrecognizedTags: false
|
||||||
preserveWhitespace: true
|
|
||||||
}
|
}
|
||||||
}); // Reconfigure for testing
|
}); // Reconfigure for testing
|
||||||
|
|
||||||
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
expect(markoCompiler.config.ignoreUnrecognizedTags).to.equal(false);
|
||||||
expect(markoCompiler.config.preserveWhitespace).to.equal(true);
|
|
||||||
|
|
||||||
compileAndCheck("./a.marko", true /* should write to disk */);
|
compileAndCheck("./invalid.marko", true /* should error */);
|
||||||
|
|
||||||
requireHook.install({
|
requireHook.install({
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
writeToDisk: false,
|
ignoreUnrecognizedTags: true
|
||||||
preserveWhitespace: false
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(markoCompiler.config.writeToDisk).to.equal(false);
|
expect(markoCompiler.config.ignoreUnrecognizedTags).to.equal(true);
|
||||||
expect(markoCompiler.config.preserveWhitespace).to.equal(false);
|
|
||||||
|
|
||||||
markoCompiler.configure({
|
compileAndCheck("./invalid.marko", false /* should not error */);
|
||||||
writeToDisk: true,
|
|
||||||
preserveWhitespace: true
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
|
||||||
expect(markoCompiler.config.preserveWhitespace).to.equal(true);
|
|
||||||
|
|
||||||
compileAndCheck("./b.marko", false /* should write to disk */);
|
|
||||||
|
|
||||||
markoCompiler.configure(); // Reset to defaults
|
|
||||||
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
|
||||||
expect(markoCompiler.config.preserveWhitespace).to.equal(false);
|
|
||||||
|
|
||||||
requireHook.install({
|
|
||||||
compilerOptions: {
|
|
||||||
writeToDisk: true,
|
|
||||||
preserveWhitespace: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
compileAndCheck("./c.marko", true /* should write to disk */);
|
|
||||||
|
|
||||||
requireHook.install({
|
|
||||||
compilerOptions: {
|
|
||||||
preserveWhitespace: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
markoCompiler.configure({
|
|
||||||
writeToDisk: false,
|
|
||||||
preserveWhitespace: true
|
|
||||||
});
|
|
||||||
|
|
||||||
compileAndCheck("./d.marko", false /* should write to disk */);
|
|
||||||
|
|
||||||
done();
|
|
||||||
} finally {
|
} finally {
|
||||||
// Reset require hook.
|
markoCompiler.configure(); // Reset to defaults
|
||||||
requireHook.install({
|
expect(markoCompiler.config.ignoreUnrecognizedTags).to.equal(false);
|
||||||
compilerOptions: {
|
done();
|
||||||
writeToDisk: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,7 @@ var nodePath = require("path");
|
|||||||
|
|
||||||
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
||||||
var templatePath = nodePath.join(__dirname, "template.marko");
|
var templatePath = nodePath.join(__dirname, "template.marko");
|
||||||
var template = require(templatePath);
|
var template = require(templatePath).default;
|
||||||
template.render(
|
template.render(
|
||||||
{
|
{
|
||||||
name: "John"
|
name: "John"
|
||||||
|
|||||||
@ -11,7 +11,7 @@ exports.check = function(marko, markoCompiler, expect, snapshot, done) {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
var template = require("./template.marko");
|
var template = require("./template.marko").default;
|
||||||
template
|
template
|
||||||
.stream({
|
.stream({
|
||||||
name: "John"
|
name: "John"
|
||||||
|
|||||||
@ -7,7 +7,7 @@ chai.config.includeStack = true;
|
|||||||
|
|
||||||
var expect = require("chai").expect;
|
var expect = require("chai").expect;
|
||||||
require("../../compiler");
|
require("../../compiler");
|
||||||
var autotest = require("../autotest");
|
var autotest = require("mocha-autotest").default;
|
||||||
var marko = require("../../");
|
var marko = require("../../");
|
||||||
var markoCompiler = require("../../compiler");
|
var markoCompiler = require("../../compiler");
|
||||||
|
|
||||||
@ -25,18 +25,3 @@ autotest("fixtures", fixture => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
autotest("fixtures-deprecated", fixture => {
|
|
||||||
let test = fixture.test;
|
|
||||||
let resolve = fixture.resolve;
|
|
||||||
let snapshot = fixture.snapshot;
|
|
||||||
test(done => {
|
|
||||||
require(resolve("test.js")).check(
|
|
||||||
marko,
|
|
||||||
markoCompiler,
|
|
||||||
expect,
|
|
||||||
snapshot,
|
|
||||||
done
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ var expect = require("chai").expect;
|
|||||||
|
|
||||||
module.exports = function(helpers) {
|
module.exports = function(helpers) {
|
||||||
var component = helpers.mount(require.resolve("./index.marko"));
|
var component = helpers.mount(require.resolve("./index.marko"));
|
||||||
var hello = require("./components/app-hello");
|
var hello = require("./components/app-hello").default;
|
||||||
|
|
||||||
var renderTarget = component.getEl("renderTarget");
|
var renderTarget = component.getEl("renderTarget");
|
||||||
expect(renderTarget.innerHTML).to.equal("<span>ref</span>");
|
expect(renderTarget.innerHTML).to.equal("<span>ref</span>");
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
$ var id = macroInput.id;
|
$ var id = macroInput.id;
|
||||||
$ var label = macroInput.label;
|
$ var label = macroInput.label;
|
||||||
$ var handler = macroInput.handler;
|
$ var handler = macroInput.handler;
|
||||||
<button key=`${id}` type="button" onClick($nonstandard`${handler}`)>
|
<button key=id type="button" onClick(handler)>
|
||||||
$label
|
$label
|
||||||
</button>
|
</button>
|
||||||
</macro>
|
</macro>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var expect = require("chai").expect;
|
var expect = require("chai").expect;
|
||||||
var iframeContentComponent = require("./components/app-iframe-content");
|
var iframeContentComponent = require("./components/app-iframe-content").default;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
renderIntoIframe: function() {
|
renderIntoIframe: function() {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var helloComponent = require("./components/hello");
|
var helloComponent = require("./components/hello").default;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
onMount: function() {
|
onMount: function() {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var myTextNodeComponent = require("./components/my-text-node");
|
var myTextNodeComponent = require("./components/my-text-node").default;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
onMount: function() {
|
onMount: function() {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var helloComponent = require("./components/hello");
|
var helloComponent = require("./components/hello").default;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
onMount: function() {
|
onMount: function() {
|
||||||
|
|||||||
@ -19,7 +19,7 @@ static function handleTestEvent2() {
|
|||||||
<app-custom-events onTestEvent(handleTestEvent1) key="customEvents"/>
|
<app-custom-events onTestEvent(handleTestEvent1) key="customEvents"/>
|
||||||
<app-custom-events
|
<app-custom-events
|
||||||
onTestEvent(handleTestEvent2)
|
onTestEvent(handleTestEvent2)
|
||||||
channel=`customEvents-${__component.id}`/>
|
channel=`customEvents-${component.id}`/>
|
||||||
<ul>
|
<ul>
|
||||||
<for|color| of=["red", "green", "blue"]>
|
<for|color| of=["red", "green", "blue"]>
|
||||||
<li key="colorListItems[]">${color}</li>
|
<li key="colorListItems[]">${color}</li>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<app-custom-events onTestEvent("handleTestEvent1") key="customEvents"/>
|
<app-custom-events onTestEvent("handleTestEvent1") key="customEvents"/>
|
||||||
<app-custom-events
|
<app-custom-events
|
||||||
onTestEvent("handleTestEvent2")
|
onTestEvent("handleTestEvent2")
|
||||||
channel=`customEvents-${__component.id}`/>
|
channel=`customEvents-${component.id}`/>
|
||||||
<ul>
|
<ul>
|
||||||
<for|color| of=["red", "green", "blue"]>
|
<for|color| of=["red", "green", "blue"]>
|
||||||
<li key="colorListItems[]">${color}</li>
|
<li key="colorListItems[]">${color}</li>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<app-custom-events onTestEvent("handleTestEvent1") key="customEvents"/>
|
<app-custom-events onTestEvent("handleTestEvent1") key="customEvents"/>
|
||||||
<app-custom-events
|
<app-custom-events
|
||||||
onTestEvent("handleTestEvent2")
|
onTestEvent("handleTestEvent2")
|
||||||
channel=`customEvents-${__component.id}`/>
|
channel=`customEvents-${component.id}`/>
|
||||||
<ul>
|
<ul>
|
||||||
<for|color| of=["red", "green", "blue"]>
|
<for|color| of=["red", "green", "blue"]>
|
||||||
<li key="colorListItems[]">${color}</li>
|
<li key="colorListItems[]">${color}</li>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<app-custom-events onTestEvent("handleTestEvent1") key="customEvents"/>
|
<app-custom-events onTestEvent("handleTestEvent1") key="customEvents"/>
|
||||||
<app-custom-events
|
<app-custom-events
|
||||||
onTestEvent("handleTestEvent2")
|
onTestEvent("handleTestEvent2")
|
||||||
channel=`customEvents-${__component.id}`/>
|
channel=`customEvents-${component.id}`/>
|
||||||
<ul>
|
<ul>
|
||||||
<for|color| of=["red", "green", "blue"]>
|
<for|color| of=["red", "green", "blue"]>
|
||||||
<li key="colorListItems[]">${color}</li>
|
<li key="colorListItems[]">${color}</li>
|
||||||
|
|||||||
@ -2,7 +2,7 @@ var expect = require("chai").expect;
|
|||||||
|
|
||||||
module.exports = function(helpers) {
|
module.exports = function(helpers) {
|
||||||
var component = helpers.mount(require.resolve("./index.marko"));
|
var component = helpers.mount(require.resolve("./index.marko"));
|
||||||
var hello = require("./components/app-hello");
|
var hello = require("./components/app-hello").default;
|
||||||
|
|
||||||
var renderTarget = component.getEl("renderTarget");
|
var renderTarget = component.getEl("renderTarget");
|
||||||
var referenceElement = component.getEl("referenceElement");
|
var referenceElement = component.getEl("referenceElement");
|
||||||
|
|||||||
@ -2,7 +2,7 @@ var expect = require("chai").expect;
|
|||||||
|
|
||||||
module.exports = function(helpers, done) {
|
module.exports = function(helpers, done) {
|
||||||
var component = helpers.mount(require.resolve("./index.marko"));
|
var component = helpers.mount(require.resolve("./index.marko"));
|
||||||
var hello = require("./components/hello");
|
var hello = require("./components/hello").default;
|
||||||
|
|
||||||
var targetEl = component.getEl("target");
|
var targetEl = component.getEl("target");
|
||||||
hello
|
hello
|
||||||
|
|||||||
@ -2,7 +2,7 @@ var expect = require("chai").expect;
|
|||||||
|
|
||||||
module.exports = function(helpers) {
|
module.exports = function(helpers) {
|
||||||
var component = helpers.mount(require.resolve("./index.marko"));
|
var component = helpers.mount(require.resolve("./index.marko"));
|
||||||
var hello = require("./components/hello");
|
var hello = require("./components/hello").default;
|
||||||
|
|
||||||
var targetEl = component.getEl("target");
|
var targetEl = component.getEl("target");
|
||||||
hello.renderSync({ name: "John" }).replace(targetEl);
|
hello.renderSync({ name: "John" }).replace(targetEl);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ module.exports = function(helpers) {
|
|||||||
|
|
||||||
var initialCounter = component.getComponent("initialCounter");
|
var initialCounter = component.getComponent("initialCounter");
|
||||||
|
|
||||||
var counter = require("./components/app-counter");
|
var counter = require("./components/app-counter").default;
|
||||||
|
|
||||||
var renderTarget = component.getEl("renderTarget");
|
var renderTarget = component.getEl("renderTarget");
|
||||||
expect(renderTarget.innerHTML).to.contain("Count: 0");
|
expect(renderTarget.innerHTML).to.contain("Count: 0");
|
||||||
|
|||||||
@ -7,5 +7,5 @@ module.exports = function(helpers) {
|
|||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
component.state.foo = "bar";
|
component.state.foo = "bar";
|
||||||
}).to.throw(TypeError);
|
}).to.throw("Cannot add property foo");
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("../__util__/test-init");
|
require("../__util__/test-init");
|
||||||
|
|
||||||
var autotest = require("../autotest");
|
var autotest = require("mocha-autotest").default;
|
||||||
var createBrowserWithMarko = require("../__util__/create-marko-jsdom-module");
|
var createBrowserWithMarko = require("../__util__/create-marko-jsdom-module");
|
||||||
var ssrTemplate = require("./template.marko");
|
var ssrTemplate = require("./template.marko").default;
|
||||||
var hydrateComponentPath = require.resolve("./template.component-browser.js");
|
var hydrateComponentPath = require.resolve("./template.component-browser.js");
|
||||||
var browserHelpersPath = require.resolve("../__util__/BrowserHelpers");
|
var browserHelpersPath = require.resolve("../__util__/BrowserHelpers");
|
||||||
var testTargetHTML = '<div id="testsTarget"></div><div></div>';
|
var testTargetHTML = '<div id="testsTarget"></div><div></div>';
|
||||||
@ -15,11 +15,6 @@ autotest("fixtures", {
|
|||||||
hydrate: runHydrateTest
|
hydrate: runHydrateTest
|
||||||
});
|
});
|
||||||
|
|
||||||
autotest("fixtures-deprecated", {
|
|
||||||
client: runClientTest,
|
|
||||||
hydrate: runHydrateTest
|
|
||||||
});
|
|
||||||
|
|
||||||
function runClientTest(fixture) {
|
function runClientTest(fixture) {
|
||||||
let test = fixture.test;
|
let test = fixture.test;
|
||||||
let resolve = fixture.resolve;
|
let resolve = fixture.resolve;
|
||||||
@ -73,18 +68,14 @@ function runHydrateTest(fixture) {
|
|||||||
var browser = createBrowserWithMarko(__dirname, String(html), {
|
var browser = createBrowserWithMarko(__dirname, String(html), {
|
||||||
beforeParse(window, browser) {
|
beforeParse(window, browser) {
|
||||||
var marko = browser.require("marko/components");
|
var marko = browser.require("marko/components");
|
||||||
var legacy = browser.require("marko/legacy-components");
|
|
||||||
legacy.load = type =>
|
|
||||||
legacy.defineWidget(
|
|
||||||
browser.require(
|
|
||||||
type.replace(/^.*\/components-browser/, __dirname)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
var rootComponent = browser.require(hydrateComponentPath);
|
var rootComponent = browser.require(hydrateComponentPath);
|
||||||
|
rootComponent = rootComponent.default || rootComponent;
|
||||||
marko.register(ssrTemplate.meta.id, rootComponent);
|
marko.register(ssrTemplate.meta.id, rootComponent);
|
||||||
components.forEach(function(def) {
|
components.forEach(function(def) {
|
||||||
Object.keys(def.components).forEach(type => {
|
Object.keys(def.components).forEach(type => {
|
||||||
marko.register(type, browser.require(def.components[type]));
|
var component = browser.require(def.components[type]);
|
||||||
|
component = component.default || component;
|
||||||
|
marko.register(type, component);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var AppHello = require("../app-hello");
|
var AppHello = require("../app-hello").default;
|
||||||
|
|
||||||
module.exports = function(input, out) {
|
module.exports = function(input, out) {
|
||||||
var asyncOut = out.beginAsync();
|
var asyncOut = out.beginAsync();
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
<marko no-browser-rerender />
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
static {
|
static {
|
||||||
var markoComponents = require("marko/components");
|
var markoComponents = require("marko/components");
|
||||||
var componentsTemplate = require("./components.marko");
|
var componentsTemplate = require("./components.marko").default;
|
||||||
|
|
||||||
function componentsDataProvider(callback) {
|
function componentsDataProvider(callback) {
|
||||||
componentsTemplate.renderToString({}, function(err, html, out) {
|
componentsTemplate.renderToString({}, function(err, html, out) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var expect = require("chai").expect;
|
var expect = require("chai").expect;
|
||||||
var Component = require("./components/a/index.marko");
|
var Component = require("./components/a/index.marko").default;
|
||||||
|
|
||||||
it("should allow diffing html", function() {
|
it("should allow diffing html", function() {
|
||||||
var parentNode = document.getElementById("test-result");
|
var parentNode = document.getElementById("test-result");
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
onMount() {
|
||||||
|
var componentsLookup = window.components || (window.components = {});
|
||||||
|
componentsLookup["onInput-assign-null-and-return"] = this;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -6,11 +6,6 @@ class {
|
|||||||
name: input.name.toUpperCase()
|
name: input.name.toUpperCase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount() {
|
|
||||||
var componentsLookup = window.components || (window.components = {});
|
|
||||||
componentsLookup['onInput-assign-null-and-return'] = this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
<marko no-browser-rerender />
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
html lang="en"
|
html lang="en"
|
||||||
head
|
head
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
var expect = require("chai").expect;
|
var expect = require("chai").expect;
|
||||||
|
|
||||||
it("should allow return", function() {
|
it.skip("should allow return", function() {
|
||||||
var component = window.components["onInput-return"];
|
var component = window.components["onInput-return"];
|
||||||
|
|
||||||
expect(component.input.name).to.equal("FRANK");
|
expect(component.input.name).to.equal("FRANK");
|
||||||
@ -16,7 +16,7 @@ it("should allow return", function() {
|
|||||||
expect(component.el.querySelector(".name").innerHTML).to.equal("JOHN");
|
expect(component.el.querySelector(".name").innerHTML).to.equal("JOHN");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow input to be assigned to null", function() {
|
it.skip("should allow input to be assigned to null", function() {
|
||||||
var component = window.components["onInput-assign-null"];
|
var component = window.components["onInput-assign-null"];
|
||||||
|
|
||||||
expect(component.input).to.equal(null);
|
expect(component.input).to.equal(null);
|
||||||
@ -41,7 +41,7 @@ it("should allow input to be assigned to null", function() {
|
|||||||
expect(component.el.querySelector(".name").innerHTML).to.equal("Henry");
|
expect(component.el.querySelector(".name").innerHTML).to.equal("Henry");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow input to be assigned to null with return", function() {
|
it.skip("should allow input to be assigned to null with return", function() {
|
||||||
var component = window.components["onInput-assign-null-and-return"];
|
var component = window.components["onInput-assign-null-and-return"];
|
||||||
|
|
||||||
expect(component.input).to.equal(null);
|
expect(component.input).to.equal(null);
|
||||||
@ -66,7 +66,7 @@ it("should allow input to be assigned to null with return", function() {
|
|||||||
expect(component.el.querySelector(".name").innerHTML).to.equal("HENRY");
|
expect(component.el.querySelector(".name").innerHTML).to.equal("HENRY");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow input to be assigned to a new object", function() {
|
it.skip("should allow input to be assigned to a new object", function() {
|
||||||
var component = window.components["onInput-assign-object"];
|
var component = window.components["onInput-assign-object"];
|
||||||
|
|
||||||
expect(component.input.name).to.equal("FRANK");
|
expect(component.input.name).to.equal("FRANK");
|
||||||
@ -91,7 +91,7 @@ it("should allow input to be assigned to a new object", function() {
|
|||||||
expect(component.el.querySelector(".name").innerHTML).to.equal("Henry");
|
expect(component.el.querySelector(".name").innerHTML).to.equal("Henry");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow input to be assigned to a new object with return", function() {
|
it.skip("should allow input to be assigned to a new object with return", function() {
|
||||||
var component = window.components["onInput-assign-object-and-return"];
|
var component = window.components["onInput-assign-object-and-return"];
|
||||||
|
|
||||||
expect(component.input.name).to.equal("HEATHER");
|
expect(component.input.name).to.equal("HEATHER");
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var expect = require("chai").expect;
|
var expect = require("chai").expect;
|
||||||
var appFooComponent = require("./components/app-foo");
|
var appFooComponent = require("./components/app-foo").default;
|
||||||
|
|
||||||
it("should generate a unique ID that is different for a UI component rendered on the server and browser", function() {
|
it("should generate a unique ID that is different for a UI component rendered on the server and browser", function() {
|
||||||
var serverFooComponent = window.fooComponent;
|
var serverFooComponent = window.fooComponent;
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
<marko no-browser-rerender />
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
var expect = require("chai").expect;
|
var expect = require("chai").expect;
|
||||||
|
|
||||||
it("should handle ending </script> tag", function(done) {
|
it("should handle ending </script> tag", function() {
|
||||||
var ready = require("marko/ready");
|
expect(document.readyState).to.equal("complete");
|
||||||
|
expect(window.fooComponent.state.evil).to.equal(
|
||||||
ready(function() {
|
'</script><script>alert("hello")</script>'
|
||||||
expect(window.fooComponent.state.evil).to.equal(
|
);
|
||||||
'</script><script>alert("hello")</script>'
|
expect(window.fooComponent.componentConfig.evil).to.equal(
|
||||||
);
|
'</script><script>alert("hello")</script>'
|
||||||
expect(window.fooComponent.componentConfig.evil).to.equal(
|
);
|
||||||
'</script><script>alert("hello")</script>'
|
|
||||||
);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,12 +3,11 @@
|
|||||||
require("../__util__/test-init");
|
require("../__util__/test-init");
|
||||||
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var autotest = require("../autotest");
|
var autotest = require("mocha-autotest").default;
|
||||||
var asyncTestSuite = require("../__util__/async-test-suite");
|
var asyncTestSuite = require("../__util__/async-test-suite");
|
||||||
var createBrowserWithMarko = require("../__util__/create-marko-jsdom-module");
|
var createBrowserWithMarko = require("../__util__/create-marko-jsdom-module");
|
||||||
|
|
||||||
autotest("fixtures", run);
|
autotest("fixtures", run);
|
||||||
autotest("fixtures-deprecated", run);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a page with marko & lasso and then pipes it through jsdom, loading co-located tests.
|
* Builds a page with marko & lasso and then pipes it through jsdom, loading co-located tests.
|
||||||
@ -19,6 +18,7 @@ function run(fixture) {
|
|||||||
var testFile = resolve("tests.js");
|
var testFile = resolve("tests.js");
|
||||||
var templateFile = resolve("template.marko");
|
var templateFile = resolve("template.marko");
|
||||||
var template = require(templateFile);
|
var template = require(templateFile);
|
||||||
|
template = template.default || template;
|
||||||
return template
|
return template
|
||||||
.render({})
|
.render({})
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
module.exports = function(helpers, done) {
|
module.exports = function(helpers, done) {
|
||||||
var template = require("./template.marko");
|
var template = require("./template.marko").default;
|
||||||
|
|
||||||
template.render({ $global: { cspNonce: "abc123" } }, function(err, html) {
|
template.render({ $global: { cspNonce: "abc123" } }, function(err, html) {
|
||||||
if (!/<script.*nonce="abc123".*>/.test(html)) {
|
if (!/<script.*nonce="abc123".*>/.test(html)) {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ var expect = require("chai").expect;
|
|||||||
var markoComponents = require("marko/components");
|
var markoComponents = require("marko/components");
|
||||||
|
|
||||||
module.exports = function(helpers, done) {
|
module.exports = function(helpers, done) {
|
||||||
var template = require("./index.marko");
|
var template = require("./index.marko").default;
|
||||||
|
|
||||||
template.renderToString({}, function(err, html, out) {
|
template.renderToString({}, function(err, html, out) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
require("../__util__/test-init");
|
require("../__util__/test-init");
|
||||||
|
|
||||||
var autotest = require("../autotest");
|
var autotest = require("mocha-autotest").default;
|
||||||
|
|
||||||
autotest("fixtures", run);
|
autotest("fixtures", run);
|
||||||
autotest("fixtures-deprecated", run);
|
|
||||||
|
|
||||||
function run(fixture) {
|
function run(fixture) {
|
||||||
let test = fixture.test;
|
let test = fixture.test;
|
||||||
|
|||||||
@ -2,27 +2,24 @@ var Or = 'or';
|
|||||||
var And;
|
var And;
|
||||||
var NegateOr;
|
var NegateOr;
|
||||||
var NegateAnd = 'negate and';
|
var NegateAnd = 'negate and';
|
||||||
|
'else';
|
||||||
'else';
|
'else';
|
||||||
|
|
||||||
'else';
|
|
||||||
if (true) {
|
if (true) {
|
||||||
'else if';
|
'else if';
|
||||||
} else {
|
} else {
|
||||||
'else';
|
'else';
|
||||||
}
|
}
|
||||||
|
|
||||||
'negated if';
|
'negated if';
|
||||||
'negated if';
|
'negated if';
|
||||||
|
|
||||||
'negated if';
|
'negated if';
|
||||||
|
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
'negated if';
|
'negated if';
|
||||||
} else {
|
} else {
|
||||||
'negated else if';
|
'negated else if';
|
||||||
}
|
}
|
||||||
|
|
||||||
'alternate';
|
'alternate';
|
||||||
'negated consequent';
|
'negated consequent';
|
||||||
@ -1,49 +1,25 @@
|
|||||||
var Or = 'MARKO_DEBUG' || 'or'
|
var Or = 'or';
|
||||||
var And = 'MARKO_DEBUG' && 'and'
|
var And;
|
||||||
var NegateOr = !'MARKO_DEBUG' || 'negate or'
|
var NegateOr;
|
||||||
var NegateAnd = !'MARKO_DEBUG' && 'negate and'
|
var NegateAnd = 'negate and';
|
||||||
|
'else';
|
||||||
if ('MARKO_DEBUG') {
|
'else';
|
||||||
'if'
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('MARKO_DEBUG') 'if';
|
|
||||||
else 'else';
|
|
||||||
|
|
||||||
if ('MARKO_DEBUG') {
|
|
||||||
'if'
|
|
||||||
} else {
|
|
||||||
'else'
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('MARKO_DEBUG') {
|
|
||||||
'if'
|
|
||||||
} else if (true) {
|
|
||||||
'else if'
|
|
||||||
} else {
|
|
||||||
'else'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!'MARKO_DEBUG') {
|
|
||||||
'negated if'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!'MARKO_DEBUG') 'negated if';
|
|
||||||
else 'negated else';
|
|
||||||
|
|
||||||
if (!'MARKO_DEBUG') {
|
|
||||||
'negated if'
|
|
||||||
} else {
|
|
||||||
'negated else'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
'negated if'
|
'else if';
|
||||||
} else if (!'MARKO_DEBUG') {
|
|
||||||
'negated else if'
|
|
||||||
} else {
|
} else {
|
||||||
'negated else'
|
'else';
|
||||||
}
|
}
|
||||||
|
|
||||||
'MARKO_DEBUG' ? 'consequent' : 'alternate'
|
'negated if';
|
||||||
!'MARKO_DEBUG' ? 'negated consequent' : 'negated alternate'
|
'negated if';
|
||||||
|
'negated if';
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
'negated if';
|
||||||
|
} else {
|
||||||
|
'negated else if';
|
||||||
|
}
|
||||||
|
|
||||||
|
'alternate';
|
||||||
|
'negated consequent';
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user