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:
Michael Rawlings 2020-02-24 17:34:02 -08:00
parent c1630543fb
commit ea6736d085
No known key found for this signature in database
GPG Key ID: B9088328804D407C
177 changed files with 685 additions and 1580 deletions

View File

@ -5,40 +5,23 @@
var fs = require("fs");
var nodePath = require("path");
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
var markoCompilerPath;
var markoCompilerPath = resolveFrom(process.cwd(), "marko/compiler");
const markocPkgVersion = require("../package.json").version;
var markoPkgVersion;
try {
var markoPkgPath = resolveFrom(process.cwd(), "marko/package.json");
markoPkgVersion = require(markoPkgPath).version;
} catch (e) {
/* ignore error */
}
var markoPkgPath = resolveFrom(process.cwd(), "marko/package.json");
var markoPkgVersion = markoPkgPath && require(markoPkgPath).version;
try {
markoCompilerPath = resolveFrom(process.cwd(), "marko/compiler");
} catch (e) {
/* ignore error */
}
var markoCompiler;
if (markoCompilerPath) {
markoCompiler = require(markoCompilerPath);
} else {
markoCompiler = require("../compiler");
}
var markoCompiler = markoCompilerPath
? require(markoCompilerPath)
: require("../compiler");
var Minimatch = require("minimatch").Minimatch;
var appModulePath = require("app-module-path");
markoCompiler.defaultOptions.checkUpToDate = false;
var mmOptions = {
matchBase: true,
dot: true,
@ -84,7 +67,16 @@ var args = require("argly")
},
"--vdom -V": {
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": {
type: "boolean",
@ -132,7 +124,7 @@ var output = "html";
var isForBrowser = false;
if (args.vdom) {
if (args.vdom || args.browser) {
output = "vdom";
isForBrowser = true;
}
@ -140,6 +132,8 @@ if (args.vdom) {
var compileOptions = {
output: output,
browser: isForBrowser,
sourceOnly: false,
sourceMaps: args.sourceMaps || false,
compilerType: "markoc",
compilerVersion: markoPkgVersion || markocPkgVersion
};
@ -348,7 +342,7 @@ if (args.clean) {
context.beginAsync();
markoCompiler.compileFile(path, compileOptions, function(err, src) {
markoCompiler.compileFile(path, compileOptions, function(err, result) {
if (err) {
failed.push(
'Failed to compile "' +
@ -360,8 +354,9 @@ if (args.clean) {
return;
}
var src = result.code;
context.beginAsync();
fs.writeFile(outPath, src, { encoding: "utf8" }, function(err) {
fs.writeFile(outPath, src, "utf8", function(err) {
if (err) {
failed.push(
'Failed to write "' + path + '". Error: ' + (err.stack || err)
@ -370,6 +365,31 @@ if (args.clean) {
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++;
context.endAsync();
});

View File

@ -1,50 +1,35 @@
{
"name": "marko",
"version": "4.18.48",
"version": "5.0.0",
"license": "MIT",
"description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
"dependencies": {
"app-module-path": "^2.2.0",
"argly": "^1.0.0",
"browser-refresh-client": "^1.0.0",
"camelcase": "^5.0.0",
"char-props": "~0.1.5",
"complain": "^1.6.0",
"deresolve": "^1.1.2",
"escodegen": "^1.8.1",
"esprima": "^4.0.0",
"estraverse": "^4.3.0",
"events-light": "^1.0.0",
"he": "^1.1.0",
"htmljs-parser": "^2.7.1",
"lasso-caching-fs": "^1.0.1",
"lasso-modules-client": "^2.0.4",
"lasso-package-root": "^1.0.1",
"listener-tracker": "^2.0.0",
"minimatch": "^3.0.2",
"property-handlers": "^1.0.0",
"raptor-regexp": "^1.0.0",
"raptor-util": "^3.2.0",
"resolve-from": "^2.0.0",
"resolve-from": "^5.0.0",
"self-closing-tags": "^1.0.1",
"simple-sha1": "^2.1.0",
"strip-json-comments": "^2.0.1",
"warp10": "^2.0.1"
},
"devDependencies": {
"@marko/migrate": "^5.1.0",
"@marko/compiler": "^5.0.0",
"bluebird": "^3.4.7",
"caller-path": "^2.0.0",
"chai": "^3.3.0",
"chai": "^4.2.0",
"diffable-html": "^2.1.0",
"express": "^4.16.1",
"it-fails": "^1.0.0",
"jquery": "^3.1.1",
"it-fails": "^1.0.4",
"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",
"through2": "^2.0.1"
},
@ -52,8 +37,7 @@
"browser": {
"./compiler.js": "./compiler-browser.marko",
"./components.js": "./components-browser.marko",
"./index.js": "./index-browser.marko",
"./legacy-components.js": "./legacy-components-browser.marko"
"./index.js": "./index-browser.marko"
},
"bin": {
"markoc": "bin/markoc"
@ -66,9 +50,6 @@
"type": "git",
"url": "https://github.com/marko-js/marko.git"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"author": "Patrick Steele-Idem <pnidem@gmail.com>",
"maintainers": [
"Patrick Steele-Idem <pnidem@gmail.com>",
@ -96,22 +77,14 @@
"bin",
"dist",
"docs",
"helpers",
"src",
"browser-refresh.js",
"compiler-browser.marko",
"compiler.js",
"components-browser.marko",
"components.js",
"env.js",
"express.js",
"hot-reload.js",
"index-browser.marko",
"index.js",
"jquery.marko",
"legacy-components-browser.marko",
"legacy-components.js",
"node-require.js",
"ready.marko"
"node-require.js"
]
}

View File

@ -1,52 +1,11 @@
var config;
/* globals 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) {
config = g.__MARKO_CONFIG;
} else {
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
output: "html",
@ -63,10 +22,19 @@ if (g.__MARKO_CONFIG) {
ignoreUnrecognizedTags: false,
/**
* Controls whether or not a key should be assigned to all HTML
* and custom tags at compile-time. The default is `true`
* Whether source maps should be output with the compiled templates.
* 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) {

View File

@ -1,36 +1,26 @@
"use strict";
var Compiler = require("./Compiler");
var Walker = require("./Walker");
var Parser = require("./Parser");
var HtmlJsParser = require("./HtmlJsParser");
var Builder = require("./Builder");
var compiler = require("@marko/compiler");
var extend = require("raptor-util/extend");
var CompileContext = require("./CompileContext");
var globalConfig = require("./config");
var ok = require("assert").ok;
var fs = require("fs");
var taglib = require("../taglib");
var defaults = extend({}, globalConfig);
Object.defineProperty(exports, "defaultOptions", {
var defaultOptionsExportDefinition = {
get: function() {
return globalConfig;
},
enumerable: true,
configurable: false
});
};
Object.defineProperty(exports, "config", {
get: function() {
return globalConfig;
},
enumerable: true,
configurable: false
Object.defineProperties(exports, {
defaultOptions: defaultOptionsExportDefinition,
config: defaultOptionsExportDefinition
});
var defaultParser = new Parser(new HtmlJsParser());
function configure(newConfig) {
if (!newConfig) {
newConfig = {};
@ -38,65 +28,36 @@ function configure(newConfig) {
globalConfig = extend({}, defaults);
extend(globalConfig, newConfig);
compiler.configure(newConfig);
}
var defaultCompiler = new Compiler({
parser: defaultParser,
builder: Builder.DEFAULT_BUILDER
});
function createBuilder(options) {
return new Builder(options);
function resultCompat({ code, meta }, options = {}) {
if (options.sourceOnly !== false) {
return code;
} else {
return { code, meta };
}
}
function createWalker(options) {
return new Walker(options);
}
function isXML(path) {
return path.endsWith(".xml") || path.endsWith(".xml.marko");
}
function _compile(src, filename, userOptions, callback) {
registerCoreTaglibs();
function _compile(src, filename, userConfig, callback) {
ok(filename, '"filename" argument is required');
ok(typeof filename === "string", '"filename" argument should be a string');
var options = {};
extend(options, globalConfig);
if (userOptions) {
extend(options, userOptions);
}
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 (userConfig) {
extend(options, userConfig);
}
if (callback) {
callback(null, result);
compiler.compile(src, filename, options).then(
result => callback(null, resultCompat(result, options)),
error => callback(error)
);
} else {
return result;
return resultCompat(compiler.compileSync(src, filename, options), options);
}
}
@ -122,7 +83,6 @@ function compileForBrowser(src, filename, options, callback) {
{
output: "vdom",
meta: false,
browser: true,
sourceOnly: false
},
options
@ -160,144 +120,49 @@ function compileFileForBrowser(filename, options, callback) {
options = null;
}
options = extend(
{ output: "vdom", meta: false, browser: true, sourceOnly: false },
options
);
options = extend({ output: "vdom", meta: false, sourceOnly: false }, options);
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.compile = compile;
exports.compileForBrowser = compileForBrowser;
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.clearCaches = clearCaches;
exports.taglibLookup = taglib.lookup;
exports.taglibLoader = taglib.loader;
exports.taglibFinder = taglib.finder;
var coreTaglibsRegistered = false;
function registerCoreTaglibs() {
if (!coreTaglibsRegistered) {
coreTaglibsRegistered = true;
taglib.register(
require("../core-tags/cache/marko.json"),
require.resolve("../core-tags/cache/marko.json")
);
taglib.register(
require("../core-tags/components/marko.json"),
require.resolve("../core-tags/components/marko.json")
);
taglib.register(
require("../core-tags/core/marko.json"),
require.resolve("../core-tags/core/marko.json")
);
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")
);
// TODO: resolve these circular dep issues.
Object.defineProperties(exports, {
taglibLookup: {
get() {
return taglib.lookup;
}
},
taglibLoader: {
get() {
return taglib.loader;
}
},
taglibFinder: {
get() {
return taglib.finder;
}
},
buildTaglibLookup: {
get() {
return compiler.taglib.buildLookup;
}
}
}
});
function buildTaglibLookup(dirname) {
registerCoreTaglibs();
return taglib.buildLookup(dirname);
}
exports.buildTaglibLookup = buildTaglibLookup;
exports.clearCaches = function clearCaches() {
taglib.clearCache();
};
exports.registerTaglib = function(filePath) {
registerCoreTaglibs();
ok(typeof filePath === "string", '"filePath" should be a string');
taglib.registerFromFile(filePath);
clearCaches();
exports.clearCaches();
};
exports.isVDOMSupported = true;

View File

@ -2,7 +2,7 @@
var nativeRequire = require;
var resolveFrom = require("resolve-from");
var deresolve = require("./util/deresolve");
var deresolve = require("deresolve");
const deresolveOptions = {
shouldRemoveExt(ext) {

View File

@ -0,0 +1,5 @@
{
"env": {
"browser": true
}
}

View File

@ -1,7 +1,6 @@
{
"browser": {
"./component-globals-tag.js": "./component-globals-tag-browser.js",
"./getRequirePath.js": "./getRequirePath-browser.js",
"./init-components-tag.js": "./init-components-tag-browser.js",
"./preserve-tag.js": "./preserve-tag-browser.js"
}

View File

@ -1,20 +1,5 @@
"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() {
try {
var OutgoingMessage = require("http").OutgoingMessage;

View File

@ -1,7 +1,84 @@
if (process.env.BUNDLE) {
// you cannot load templates dynamically within a bundle
// all templates should be pre-compiled as part of the bundle
module.exports = function() {};
} else {
module.exports = require("./index-default");
"use strict";
var nodePath = require("path");
var fs = require("fs");
var Module = require("module").Module;
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;
}

View File

@ -25,66 +25,12 @@ function compile(templatePath, markoCompiler, compilerOptions) {
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;
}
function getLoadedTemplate(path) {
var cached = require.cache[path];
return cached && cached.exports.render ? cached.exports : undefined;
}
function install(options) {
options = options || {};
@ -92,10 +38,7 @@ function install(options) {
? options.require.extensions
: require.extensions;
var compilerOptions = Object.assign(
{ requireTemplates: true },
options.compilerOptions
);
var compilerOptions = options.compilerOptions;
require("../compiler").configure(compilerOptions);
var extensions = [];
@ -113,15 +56,6 @@ function install(options) {
}
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
// marko template file on disk using the "resolve-from" module.
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
// source code that is being loaded. This allows stack traces to match up.
module._compile(compiledSrc, targetFile);
module._compile(compiledSrc, filename);
}
requireExtensions[MARKO_EXTENSIONS] =

View File

@ -0,0 +1,5 @@
{
"env": {
"browser": true
}
}

View File

@ -22,6 +22,7 @@ var domData = require("./dom-data");
var componentsByDOMNode = domData.___componentByDOMNode;
var CONTEXT_KEY = "__subtree_context__";
var hasOwnProperty = Object.prototype.hasOwnProperty;
var slice = Array.prototype.slice;
var COMPONENT_SUBSCRIBE_TO_OPTIONS;
@ -97,7 +98,7 @@ function processUpdateHandlers(component, stateChanges, oldState) {
var handlers;
for (var propName in stateChanges) {
if (stateChanges.hasOwnProperty(propName)) {
if (hasOwnProperty.call(stateChanges, propName)) {
var handlerMethodName = "update_" + propName;
handlerMethod = component[handlerMethodName];
@ -245,23 +246,19 @@ Component.prototype = componentProto = {
},
getEl: function(key, index) {
if (key) {
var resolvedKey = resolveKeyHelper(key, index);
var keyedElement = this.___keyedElements["@" + resolvedKey];
var keyedElement = this.___keyedElements[
"@" + resolveKeyHelper(key, index)
];
if (!keyedElement) {
var keyedComponentRoot = this.___keyedElements[resolvedKey];
if (keyedComponentRoot) {
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
complain(
"Accessing the elements of a child component using 'component.getEl' is deprecated."
);
}
return keyedComponentRoot.nodeType === 1 /** Node.ELEMENT_NODE */
? keyedComponentRoot
: walkFragments(keyedComponentRoot);
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
if (
keyedElement &&
keyedElement.nodeType !== 1 /* Node.ELEMENT_NODE */
) {
throw new Error(
"Using 'getEl(key)' to get a component instance is not supported, did you mean 'getComponent(key)'?"
);
}
}
@ -283,20 +280,20 @@ Component.prototype = componentProto = {
return els;
},
getComponent: function(key, index) {
var rootNode = this.___keyedElements[resolveKeyHelper(key, index)];
if (/\[\]$/.test(key)) {
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
complain(
var rootNode = this.___keyedElements["@" + resolveKeyHelper(key, index)];
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
if (/\[\]$/.test(key)) {
throw new Error(
"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);
},
getComponents: function(key) {
var lookup = this.___keyedElements[key + "[]"];
var lookup = this.___keyedElements["@" + key + "[]"];
return lookup
? Object.keys(lookup)
.map(function(key) {
@ -388,7 +385,7 @@ Component.prototype = componentProto = {
// Merge in the new state with the old state
var newState = name;
for (var k in newState) {
if (newState.hasOwnProperty(k)) {
if (hasOwnProperty.call(newState, k)) {
state.___set(k, newState[k], true /* ensure:true */);
}
}

View File

@ -93,21 +93,17 @@ ComponentDef.___deserialize = function(o, types, global, registry) {
var input = o[2];
var extra = o[3];
var isLegacy = extra.l;
var state = extra.s;
var componentProps = extra.w;
var flags = extra.f;
var component =
typeName /* legacy */ &&
registry.___createComponent(typeName, id, isLegacy);
var component = registry.___createComponent(typeName, id);
// Prevent newly created component from being queued for update since we area
// just building it from the server info
component.___updateQueued = true;
if (
!isLegacy &&
flags & FLAG_WILL_RERENDER_IN_BROWSER &&
!(flags & FLAG_OLD_HYDRATE_NO_CREATE)
) {

View File

@ -13,22 +13,17 @@ module.exports = function beginComponent(
key,
ownerComponentDef,
isSplitComponent,
isImplicitComponent,
existingComponentDef
isImplicitComponent
) {
var globalContext = componentsContext.___globalContext;
var componentId = component.id;
// existingComponentDef is only here to allow binding a conditional
// widget. It should be removed when the legacy compat layer is removed.
var componentDef =
existingComponentDef ||
(componentsContext.___componentDef = new ComponentDef(
component,
componentId,
globalContext
));
var componentDef = (componentsContext.___componentDef = new ComponentDef(
component,
componentId,
globalContext
));
// On the server
if (

View File

@ -89,7 +89,6 @@ function addComponentsFromContext(componentsContext, componentsToHydrate) {
d: componentDef.___domEvents,
e: customEvents,
f: flags ? flags : undefined,
l: componentDef.___isLegacy,
p: customEvents && scope, // Only serialize scope if we need to attach custom events
r: componentDef.___boundary,
s: state,

View File

@ -164,10 +164,6 @@ function addDOMEventListeners(
function initComponent(componentDef, doc) {
var component = componentDef.___component;
if (!component || !component.___isComponent) {
return; // legacy
}
component.___reset();
component.___document = doc;

View File

@ -4,8 +4,6 @@
"./endComponent.js": "./endComponent-browser.js",
"./index.js": "./index-browser.js",
"./init-components.js": "./init-components-browser.js",
"./legacy/defineWidget-legacy.js":
"./legacy/defineWidget-legacy-browser.js",
"./registry.js": "./registry-browser.js",
"./util.js": "./util-browser.js"
}

View File

@ -19,8 +19,6 @@
- Fixes for IE <=10
*/
/* globals window */
var isReady = false;
var readyBound = false;

View File

@ -1,6 +1,4 @@
var complain = "MARKO_DEBUG" && require("complain");
var defineComponent = require("./defineComponent");
var loader = require("../../loader");
require(".");
var registered = {};
@ -14,23 +12,13 @@ function register(componentId, def) {
return componentId;
}
function load(typeName, isLegacy) {
function load(typeName) {
var target = loaded[typeName];
if (!target) {
target = registered[typeName];
if (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) {
@ -43,14 +31,14 @@ function load(typeName, isLegacy) {
return target;
}
function getComponentClass(typeName, isLegacy) {
function getComponentClass(typeName) {
var ComponentClass = componentTypes[typeName];
if (ComponentClass) {
return ComponentClass;
}
ComponentClass = load(typeName, isLegacy);
ComponentClass = load(typeName);
ComponentClass = ComponentClass.Component || ComponentClass;
@ -94,8 +82,8 @@ function getComponentClass(typeName, isLegacy) {
return ComponentClass;
}
function createComponent(typeName, id, isLegacy) {
var ComponentClass = getComponentClass(typeName, isLegacy);
function createComponent(typeName, id) {
var ComponentClass = getComponentClass(typeName);
return new ComponentClass(id);
}

View File

@ -221,7 +221,3 @@ function createRendererFunc(
}
module.exports = createRendererFunc;
// exports used by the legacy renderer
createRendererFunc.___resolveComponentKey = resolveComponentKey;
createRendererFunc.___trackAsyncComponents = trackAsyncComponents;

View File

@ -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 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 prefix + nextId++;
};

View File

@ -1,5 +1,7 @@
"use strict";
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Merges object properties
*/
@ -9,7 +11,7 @@ module.exports = function assign() {
var source = arguments[i];
if (source != null) {
for (var k in source) {
if (source.hasOwnProperty(k)) {
if (hasOwnProperty.call(source, k)) {
into[k] = source[k];
}
}

View File

@ -27,13 +27,13 @@ module.exports = function dynamicTag(
customEvents
) {
if (tag) {
if (tag.default) {
tag = tag.default;
}
var attrs = getAttrs && getAttrs();
var component = componentDef && componentDef.___component;
if (typeof tag === "string") {
if (isNaN(key)) {
key = "@" + key;
}
if (customEvents) {
if (!props) {
props = {};
@ -93,18 +93,14 @@ module.exports = function dynamicTag(
var render = (tag && tag.renderBody) || tag;
var isFn = typeof render === "function";
if (render.safeHTML) {
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
complain(
"Using `<include(x)/>` or the `<${dynamic}/>` tags with a `{ safeHTML: ... }` object is deprecated. Use the unescaped text placeholder syntax instead."
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
if (render.safeHTML || render.toHTML) {
throw new Error(
"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) {
var flags = componentDef ? componentDef.___flags : 0;
var willRerender = flags & FLAG_WILL_RERENDER_IN_BROWSER;

View File

@ -1,9 +1,11 @@
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Merges object properties
*/
module.exports = function merge(into, 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];
}
}

View File

@ -219,8 +219,6 @@ var proto = (AsyncStream.prototype = {
}
state.events.emit("beginAsync", {
writer: newStream, // Legacy
parentWriter: this, // Legacy
out: newStream,
parentOut: this
});

View File

@ -2,8 +2,6 @@
var escape = require("./escape-xml");
var escapeDoubleQuotes = escape.d;
var escapeSingleQuotes = escape.s;
var complain = "MARKO_DEBUG" && require("complain");
module.exports = function attr(name, value) {
if (value == null || value === false) {
@ -16,28 +14,14 @@ module.exports = function attr(name, value) {
return result;
}
var type = typeof value;
result += "=";
if (type === "number") {
if (typeof value === "number") {
return result + value;
}
if (type == "object") {
switch (value.toString) {
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);
}
if (value instanceof RegExp) {
return result + doubleQuote(value.source);
}
return result + doubleQuote(value);
@ -46,7 +30,3 @@ module.exports = function attr(name, value) {
function doubleQuote(value) {
return '"' + escapeDoubleQuotes(value) + '"';
}
function singleQuote(value) {
return "'" + escapeSingleQuotes(value) + "'";
}

View File

@ -1,6 +1,5 @@
"use strict";
var complain = "MARKO_DEBUG" && require("complain");
var changeCase = require("../../helpers/_change-case");
var attrHelper = require("./attr");
var classAttrHelper = require("./class-attr");
@ -11,31 +10,34 @@ var invalidAttrNameCharacters = /[\s'"</=\\]/u;
var validAttrs = Object.create(null);
var invalidAttrs = Object.create(null);
module.exports = function attrs(arg) {
if (typeof arg === "object") {
var out = "";
for (var attrName in arg) {
if (attrName === "style") {
out += styleAttrHelper(arg[attrName]);
} else if (attrName === "class") {
out += classAttrHelper(arg[attrName]);
} else if (attrName !== "renderBody" && isValidAttrName(attrName)) {
out += attrHelper(
changeCase.___camelToDashCase(attrName),
arg[attrName]
module.exports = function attrs(attributes) {
if (attributes != null) {
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
if (typeof attributes !== "object") {
throw new Error(
"A non object was passed as a dynamic attributes value."
);
}
}
return out;
} else if (typeof arg === "string") {
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
complain(
"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"
);
var result = "";
for (var attrName in attributes) {
if (attrName === "style") {
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 "";
};

View File

@ -1,38 +1,33 @@
"use strict";
var complain = "MARKO_DEBUG" && require("complain");
var attrsHelper = require("./attrs");
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Merges attribute objects into a string.
*/
module.exports = function mergeAttrs() {
var result = "";
var currentAttrs = {};
var finalAttributes = {};
for (var i = 0; i < arguments.length; i++) {
var source = arguments[i];
if (typeof source === "string") {
var attributes = arguments[i];
if (attributes != null) {
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
complain(
"Passing a string as dynamic attributes ('<div ${string}>' or '<div ...string>') is deprecated, use an object instead."
);
if (typeof attributes !== "object") {
throw new Error(
"A non object was passed as a dynamic attributes value."
);
}
}
if (source[0] !== " ") {
source = " " + source;
}
result += attrsHelper(currentAttrs) + source;
currentAttrs = {};
} else if (source != null) {
for (var k in source) {
if (source.hasOwnProperty(k)) {
currentAttrs[k] = source[k];
for (var k in attributes) {
if (hasOwnProperty.call(attributes, k)) {
finalAttributes[k] = attributes[k];
}
}
}
}
return result + attrsHelper(currentAttrs);
return result + attrsHelper(finalAttributes);
};

View File

@ -1,5 +1,3 @@
/* globals window */
var win = window;
var setImmediate = win.setImmediate;

View File

@ -1,12 +1,12 @@
/* jshint newcap:false */
var complain = "MARKO_DEBUG" && require("complain");
var domData = require("../components/dom-data");
var vElementByDOMNode = domData.___vElementByDOMNode;
var VNode = require("./VNode");
var inherit = require("raptor-util/inherit");
var ATTR_XLINK_HREF = "xlink:href";
var xmlnsRegExp = /^xmlns(:|$)/;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var NS_XLINK = "http://www.w3.org/1999/xlink";
var NS_HTML = "http://www.w3.org/1999/xhtml";
var NS_MATH = "http://www.w3.org/1998/Math/MathML";
@ -28,18 +28,8 @@ function convertAttrValue(type, value) {
if (value === true) {
return "";
} else if (type == "object") {
switch (value.toString) {
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 JSON.stringify(value);
case RegExp.prototype.toString:
return value.source;
if (value instanceof RegExp) {
return value.source;
}
}
@ -48,7 +38,7 @@ function convertAttrValue(type, value) {
function assign(a, b) {
for (var key in b) {
if (b.hasOwnProperty(key)) {
if (hasOwnProperty.call(b, key)) {
a[key] = b[key];
}
}

View File

@ -1,6 +1,5 @@
"use strict";
var complain = "MARKO_DEBUG" && require("complain");
var changeCase = require("../../helpers/_change-case");
var classHelper = require("../../helpers/class-value");
var styleHelper = require("../../helpers/style-value");
@ -9,17 +8,16 @@ var styleHelper = require("../../helpers/style-value");
* Helper for processing dynamic attributes
*/
module.exports = function(attributes) {
if (typeof attributes === "string") {
if (attributes != null) {
// eslint-disable-next-line no-constant-condition
if ("MARKO_DEBUG") {
complain(
"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"
);
if (typeof attributes !== "object") {
throw new Error(
"A non object was passed as a dynamic attributes value."
);
}
}
return parseAttrs(attributes);
}
if (attributes) {
var newAttributes = {};
for (var attrName in attributes) {
@ -44,23 +42,3 @@ module.exports = function(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;
}

View File

@ -2,10 +2,11 @@
var taglibLoader = require("../taglib-loader");
var nodePath = require("path");
var lassoPackageRoot = require("lasso-package-root");
var resolveFrom = require("resolve-from");
var resolveFrom = require("resolve-from").silent;
var scanTagsDir = require("../taglib-loader/scanTagsDir");
var DependencyChain = require("../taglib-loader/DependencyChain");
var lassoCachingFS = require("lasso-caching-fs");
var hasOwnProperty = Object.prototype.hasOwnProperty;
var findCache = {};
var excludedDirs = {};
@ -70,7 +71,7 @@ function find(dirname, registeredTaglibs) {
var helper = {
alreadyAdded: function(taglibPath) {
return added.hasOwnProperty(taglibPath);
return hasOwnProperty.call(added, taglibPath);
},
addTaglib: function(taglib) {
if (added[taglib.path]) {

View File

@ -1,22 +1,10 @@
"use strict";
var forEachEntry = require("raptor-util/forEachEntry");
var ok = require("assert").ok;
var CustomTag;
var path = require("path");
var markoModules = require("../../compiler/modules");
var complain = require("complain");
var coreTagsPath = path.join(__dirname, "../../core-tags");
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);
};
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
class Tag {
constructor(filePath) {
@ -55,30 +43,6 @@ class Tag {
// 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) {
forEachEntry(this.transformers, function(key, transformer) {
callback.call(thisObj, transformer);
@ -87,7 +51,7 @@ class Tag {
hasTransformers() {
/*jshint unused:false */
for (var k in this.transformers) {
if (this.transformers.hasOwnProperty(k)) {
if (hasOwnProperty.call(this.transformers, k)) {
return true;
}
}
@ -96,12 +60,6 @@ class Tag {
checkDeprecatedAttr(attr) {
attr.filePath = this.filePath;
if (attr.name === "key" && !this.isCoreTag()) {
complain("@key property is deprecated", {
location: this.filePath
});
}
//
if (attr.setFlag && attr.setFlag !== "hasComponentEvents") {
complain(`${attr.name} - : set-flag property is deprecated`, {
location: this.filePath
@ -130,17 +88,8 @@ class Tag {
if (attr.name === "*") {
attr.dynamicAttribute = true;
if (attr.targetProperty === null || attr.targetProperty === "") {
if (attr.targetProperty === undefined || attr.targetProperty === "") {
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) {
for (var attrName in this.attributes) {
if (this.attributes.hasOwnProperty(attrName)) {
if (hasOwnProperty.call(this.attributes, attrName)) {
callback.call(thisObj, this.attributes[attrName]);
}
}
@ -178,57 +127,15 @@ class Tag {
}
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) {
var key = transformer.path;
transformer.taglibId = this.taglibId;
this.transformers[key] = transformer;
}
/**
* DEPRECATED
*/
setBodyFunction(name, params) {
this.bodyFunction = {
__noMerge: true,
name: name,
params: params
};
}
/**
* DEPRECATED
*/
setBodyProperty(propertyName) {
this.bodyProperty = propertyName;
}
addNestedTag(nestedTag) {
ok(nestedTag.name, '"nestedTag.name" is required');
@ -266,41 +173,6 @@ class Tag {
.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() {
return this;
}
@ -309,10 +181,6 @@ class Tag {
this.taglibId = taglib ? taglib.id : null;
this.taglibPath = taglib ? taglib.path : null;
}
isCoreTag() {
return this.filePath && this.filePath.startsWith(coreTagsPath);
}
}
module.exports = Tag;

View File

@ -4,10 +4,11 @@ var ok = require("assert").ok;
var path = require("path");
var loaders = require("./loaders");
var markoModules = require("../../compiler/modules");
var hasOwnProperty = Object.prototype.hasOwnProperty;
function handleImport(taglib, importedTaglib) {
var importsLookup = taglib.importsLookup || (taglib.importsLookup = {});
if (importsLookup.hasOwnProperty(importedTaglib.path)) {
if (hasOwnProperty.call(importsLookup, importedTaglib.path)) {
return;
}

View File

@ -5,6 +5,7 @@ var raptorRegexp = require("raptor-regexp");
var propertyHandlers = require("property-handlers");
var types = require("./types");
var createError = require("raptor-util/createError");
var hasOwnProperty = Object.prototype.hasOwnProperty;
class AttrLoader {
constructor(attr, dependencyChain) {
@ -236,7 +237,7 @@ function loadAttributeFromProps(attrName, attrProps, dependencyChain) {
}
loadAttributeFromProps.isSupportedProperty = function(name) {
return AttrLoader.prototype.hasOwnProperty(name);
return hasOwnProperty.call(AttrLoader.prototype, name);
};
module.exports = loadAttributeFromProps;

View File

@ -5,14 +5,11 @@ var propertyHandlers = require("property-handlers");
var isObjectEmpty = require("raptor-util/isObjectEmpty");
var nodePath = require("path");
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 markoCompiler = require("../../compiler");
var createError = require("raptor-util/createError");
var types = require("./types");
var loaders = require("./loaders");
var complain = require("complain");
var hasOwnProperty = Object.prototype.hasOwnProperty;
function exists(path) {
try {
@ -35,7 +32,7 @@ function hasAttributes(tagProps) {
}
for (var name in tagProps) {
if (tagProps.hasOwnProperty(name) && name.startsWith("@")) {
if (hasOwnProperty.call(tagProps, name) && name.startsWith("@")) {
return true;
}
}
@ -74,7 +71,7 @@ function addTransformer(tagLoader, value) {
var properties =
transformer.properties || (transformer.properties = {});
for (var k in value) {
if (value.hasOwnProperty(k)) {
if (hasOwnProperty.call(value, k)) {
properties[k] = value[k];
}
}
@ -203,7 +200,7 @@ class TagLoader {
if (value != null && typeof value === "object") {
for (k in value) {
if (value.hasOwnProperty(k)) {
if (hasOwnProperty.call(value, k)) {
if (k.startsWith("@") || k.startsWith("<")) {
// Move over all of the attributes and nested tags
// to the tag definition.
@ -421,18 +418,6 @@ class TagLoader {
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
* 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.
*/
@ -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) {
this.tag.openTagOnly = value;
}
/**
* DEPRECATED
*/
noOutput(value) {
this.tag.noOutput = value;
}
/**
* The description of the tag. Only used for documentation.
*/
@ -688,13 +517,6 @@ class TagLoader {
this.tag.deprecated = value;
}
/**
* DEPRECATED: use parse-options.ignoreAttributes instead
*/
parseAttributes(value) {
this.tag.parseAttributes = value;
}
attributeGroups(value) {
if (!value) {
return;
@ -719,7 +541,7 @@ class TagLoader {
}
function isSupportedProperty(name) {
return TagLoader.prototype.hasOwnProperty(name);
return hasOwnProperty.call(TagLoader.prototype, name);
}
function loadTagFromProps(tag, tagProps, dependencyChain) {

View File

@ -11,6 +11,7 @@ var resolveFrom = typeof window === "undefined" && require("resolve-from"); // N
var DependencyChain = require("./DependencyChain");
var createError = require("raptor-util/createError");
var loaders = require("./loaders");
var hasOwnProperty = Object.prototype.hasOwnProperty;
function exists(path) {
try {
@ -213,7 +214,7 @@ class TaglibLoader {
// }
for (var tagName in tags) {
if (tags.hasOwnProperty(tagName)) {
if (hasOwnProperty.call(tags, tagName)) {
this._handleTag(
tagName,
tags[tagName],

View File

@ -2,6 +2,4 @@ exports.Taglib = require("./Taglib");
exports.Tag = require("./Tag");
exports.Attribute = require("./Attribute");
exports.Property = require("./Property");
exports.NestedVariable = require("./NestedVariable"); // DEPRECATED
exports.ImportedVariable = require("./ImportedVariable"); // DEPRECATED
exports.Transformer = require("./Transformer");

View File

@ -2,8 +2,8 @@
var ok = require("assert").ok;
var taglibTypes = require("../taglib-loader/types");
var Text = require("../../compiler/ast/Text");
var extend = require("raptor-util/extend");
var hasOwnProperty = Object.prototype.hasOwnProperty;
function transformerComparator(a, b) {
a = a.priority;
@ -28,7 +28,7 @@ function TAG_COMPARATOR(a, b) {
function merge(target, source) {
for (var k in source) {
if (source.hasOwnProperty(k)) {
if (hasOwnProperty.call(source, k)) {
if (
target[k] &&
typeof target[k] === "object" &&
@ -85,7 +85,7 @@ class TaglibLookup {
}
hasTaglib(taglib) {
return this.taglibsById.hasOwnProperty(taglib.id);
return hasOwnProperty.call(this.taglibsById, taglib.id);
}
_mergeNestedTags(taglib) {
@ -120,7 +120,7 @@ class TaglibLookup {
ok(taglib, '"taglib" is required');
ok(taglib.id, '"taglib.id" expected');
if (this.taglibsById.hasOwnProperty(taglib.id)) {
if (hasOwnProperty.call(this.taglibsById, taglib.id)) {
return;
}
@ -160,7 +160,7 @@ class TaglibLookup {
var tags = this.merged.tags;
if (tags) {
for (var tagName in tags) {
if (tags.hasOwnProperty(tagName)) {
if (hasOwnProperty.call(tags, tagName)) {
var tag = tags[tagName];
var result = callback(tag);
if (result === false) {
@ -199,7 +199,7 @@ class TaglibLookup {
}
for (var attrName in attributes) {
if (attributes.hasOwnProperty(attrName)) {
if (hasOwnProperty.call(attributes, attrName)) {
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) {
if (typeof element === "string") {
element = {
@ -449,7 +438,7 @@ class TaglibLookup {
var inputFilesSet = {};
for (var taglibId in this.taglibsById) {
if (this.taglibsById.hasOwnProperty(taglibId)) {
if (hasOwnProperty.call(this.taglibsById, taglibId)) {
var taglibInputFiles = this.taglibsById[taglibId].getInputFiles();
var len = taglibInputFiles.length;
if (len) {

View File

@ -54,6 +54,7 @@ BrowserHelpers.prototype = {
mount: function(templatePath, input) {
var $global = input && input.$global;
var template = require(templatePath);
template = template.default || template;
var renderResult = template.renderSync(input).appendTo(this.targetEl);
var instance;

View File

@ -1,23 +1,25 @@
const path = require("path");
const getComponents = (module.exports = (template, components) => {
var meta = template.meta;
const meta = template.meta;
components = components || {};
if (meta) {
if (!components[meta.id]) {
if (meta.id && meta.component) {
components[meta.id] = path.resolve(
path.dirname(template.path),
meta.component
);
}
const dir = path.dirname(template.path);
components[meta.id] =
meta.component && /-browser/.test(meta.component)
? path.resolve(dir, meta.component)
: template.path;
if (meta.tags) {
const dir = path.dirname(template.path);
meta.tags.forEach(tagRelativePath => {
var tagPath =
"." === tagRelativePath[0]
? path.resolve(path.dirname(template.path), tagRelativePath)
? path.resolve(dir, tagRelativePath)
: tagRelativePath;
var tagTemplate = require(tagPath);
tagTemplate = tagTemplate.default || tagTemplate;
components = getComponents(tagTemplate, components);
});
}

View File

@ -1,6 +1,5 @@
"use strict";
const jQuery = require("jquery");
const createBrowser = require("jsdom-context-require");
const compiler = require("../../compiler");
const globals = [
@ -30,7 +29,6 @@ module.exports = function(dir, html, options) {
beforeParse(window, browser) {
window.global = window;
window.alert = () => {};
jQuery(window);
browser.require("complain").log = (...args) =>
require("complain").log(...args);
globals.forEach(function(k) {

View File

@ -11,21 +11,22 @@ var markoDir = isDebug
? nodePath.join(rootDir, "src")
: nodePath.join(rootDir, "dist");
var markoInstalledDir = nodePath.join(rootDir, "node_modules/marko");
if (fs.existsSync(markoInstalledDir)) {
fs.renameSync(
markoInstalledDir,
nodePath.join(rootDir, "node_modules/~marko")
);
try {
var markoInstalledDir = nodePath.dirname(require.resolve("marko"));
if (fs.existsSync(markoInstalledDir)) {
fs.renameSync(
markoInstalledDir,
markoInstalledDir.replace("node_modules/marko", "node_modules/~marko")
);
}
} catch (e) {
// ignore error
}
Module._resolveFilename = function(request, parent, isMain) {
if (request.charAt(0) !== ".") {
if (request.charAt(0) !== "." && parent.filename.startsWith(rootDir)) {
if (
request === "marko/components" ||
request === "marko/jquery" ||
request === "marko/legacy-components" ||
request === "marko/ready" ||
request === "marko/env" ||
request.startsWith("marko/dist/") ||
request.startsWith("marko/src/") ||

View File

@ -1,6 +1,5 @@
require("./patch-module");
require("../../node-require").install({
compilerOptions: { writeToDisk: false },
extensions: [".marko", ".html"]
});
require("it-fails");

View File

@ -1,27 +1 @@
"use strict";
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._);
"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._);

View File

@ -1,27 +1 @@
"use strict";
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._);
"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._);

View File

@ -1,27 +1 @@
"use strict";
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._);
"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._);

View File

@ -3,7 +3,7 @@ var path = require("path");
var markoVersion = require("../../../../package.json").version;
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) {

View File

@ -1,27 +1 @@
"use strict";
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._);
"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._);

View File

@ -1,19 +1,17 @@
exports.check = function(marko, markoCompiler, expect, helpers, done) {
var compiler = require("marko/compiler");
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.ignoreUnrecognizedTags).to.equal(false);
compiler.configure({
preserveWhitespace: true
ignoreUnrecognizedTags: true
});
expect(compiler.config.writeToDisk).to.equal(true);
expect(compiler.config.preserveWhitespace).to.equal(true);
expect(compiler.config.writeVersionComment).to.equal(true);
expect(compiler.config.ignoreUnrecognizedTags).to.equal(true);
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.ignoreUnrecognizedTags).to.equal(false);
done();
};

View File

@ -6,7 +6,7 @@ var chai = require("chai");
chai.config.includeStack = true;
var expect = require("chai").expect;
require("../../compiler");
var autotest = require("../autotest");
var autotest = require("mocha-autotest").default;
var marko = require("../../");
var markoCompiler = require("../../compiler");

View File

@ -1 +1 @@
<% throw new Error('Test'); %>
$ throw new Error('Test');

View File

@ -0,0 +1 @@
<missing-tag></missing-tag>

View File

@ -0,0 +1 @@
Hello Frank!

View File

@ -0,0 +1 @@
<missing-tag/>

View File

@ -0,0 +1 @@
Hello Frank!

View File

@ -1,5 +1,4 @@
var nodePath = require("path");
var fs = require("fs");
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
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
templatePath = nodePath.join(__dirname, "dummy.marko");
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
templatePath = nodePath.join(__dirname, "dummy.marko");
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
delete markoCompiler.defaultOptions.writeToDisk;
templatePath = nodePath.join(__dirname, "invalid-template.marko");
templatePath = nodePath.join(__dirname, "template.marko");
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);
template = marko.load(templatePath, { ignoreUnrecognizedTags: true });
expect(template.render).to.be.a("function");
snapshot(template.renderSync({ name: "Frank" }).toString());
snapshot(template.renderSync({}).toString(), { name: "custom-options" });
done();
};

View File

@ -8,7 +8,7 @@ exports.check = function(marko, markoCompiler, expect, snapshot, done) {
output += data;
});
var runtimeHtml = require("marko/src/html");
var runtimeHtml = require("marko/runtime/html");
var out = runtimeHtml.createWriter(stream);
out

View File

@ -1,7 +1,7 @@
var nodePath = require("path");
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
var runtimeHtml = require("marko/html");
var runtimeHtml = require("marko/runtime/html");
var out = runtimeHtml.createWriter();
out

View File

@ -6,7 +6,7 @@ exports.check = function(marko, markoCompiler, expect, snapshot, done) {
try {
var templatePath = nodePath.join(__dirname, "template.marko");
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(template.render).to.be.a("function");
snapshot(template.renderSync({ name: "Frank" }).toString());

View File

@ -1,5 +1,5 @@
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
var template = require("./template.marko");
var template = require("./template.marko").default;
var data = {
name: "John"
};

View File

@ -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
marko.load(nodePath.join(__dirname, "template.marko"));
var templateModule = require(nodePath.join(__dirname, "template.marko.js"));
var template = marko.load(templateModule);
var template = require(nodePath.join(__dirname, "template.marko")).default;
template.render(
{
name: "John"

View File

@ -0,0 +1 @@
<missing-tag/>

View File

@ -1,89 +1,47 @@
var expect = require("chai").expect;
var fs = require("fs");
var requireHook = require("../../../../node-require");
function compileAndCheck(path, shouldWriteToDisk) {
function compileAndCheck(path, shouldHaveErrored) {
var resolved = require.resolve(path);
var compiledFile = resolved + ".js";
var err;
try {
fs.unlinkSync(compiledFile);
} catch (e) {
/* ignore error */
require(resolved);
} catch (_e) {
err = _e;
}
require(resolved);
expect(fs.existsSync(compiledFile)).to.equal(shouldWriteToDisk);
if (shouldHaveErrored) {
expect(err).is.an.instanceOf(Error);
} else {
expect(err).to.equal(undefined);
}
}
exports.check = function(marko, markoCompiler, expect, helpers, done) {
try {
requireHook.install({
compilerOptions: {
writeToDisk: true,
preserveWhitespace: true
ignoreUnrecognizedTags: false
}
}); // Reconfigure for testing
expect(markoCompiler.config.writeToDisk).to.equal(true);
expect(markoCompiler.config.preserveWhitespace).to.equal(true);
expect(markoCompiler.config.ignoreUnrecognizedTags).to.equal(false);
compileAndCheck("./a.marko", true /* should write to disk */);
compileAndCheck("./invalid.marko", true /* should error */);
requireHook.install({
compilerOptions: {
writeToDisk: false,
preserveWhitespace: false
ignoreUnrecognizedTags: true
}
});
expect(markoCompiler.config.writeToDisk).to.equal(false);
expect(markoCompiler.config.preserveWhitespace).to.equal(false);
expect(markoCompiler.config.ignoreUnrecognizedTags).to.equal(true);
markoCompiler.configure({
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();
compileAndCheck("./invalid.marko", false /* should not error */);
} finally {
// Reset require hook.
requireHook.install({
compilerOptions: {
writeToDisk: false
}
});
markoCompiler.configure(); // Reset to defaults
expect(markoCompiler.config.ignoreUnrecognizedTags).to.equal(false);
done();
}
};

View File

@ -2,7 +2,7 @@ var nodePath = require("path");
exports.check = function(marko, markoCompiler, expect, snapshot, done) {
var templatePath = nodePath.join(__dirname, "template.marko");
var template = require(templatePath);
var template = require(templatePath).default;
template.render(
{
name: "John"

View File

@ -11,7 +11,7 @@ exports.check = function(marko, markoCompiler, expect, snapshot, done) {
done();
});
var template = require("./template.marko");
var template = require("./template.marko").default;
template
.stream({
name: "John"

View File

@ -7,7 +7,7 @@ chai.config.includeStack = true;
var expect = require("chai").expect;
require("../../compiler");
var autotest = require("../autotest");
var autotest = require("mocha-autotest").default;
var marko = require("../../");
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
);
});
});

View File

@ -2,7 +2,7 @@ var expect = require("chai").expect;
module.exports = function(helpers) {
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");
expect(renderTarget.innerHTML).to.equal("<span>ref</span>");

View File

@ -4,7 +4,7 @@
$ var id = macroInput.id;
$ var label = macroInput.label;
$ var handler = macroInput.handler;
<button key=`${id}` type="button" onClick($nonstandard`${handler}`)>
<button key=id type="button" onClick(handler)>
$label
</button>
</macro>

View File

@ -1,5 +1,5 @@
var expect = require("chai").expect;
var iframeContentComponent = require("./components/app-iframe-content");
var iframeContentComponent = require("./components/app-iframe-content").default;
module.exports = {
renderIntoIframe: function() {

View File

@ -1,4 +1,4 @@
var helloComponent = require("./components/hello");
var helloComponent = require("./components/hello").default;
module.exports = {
onMount: function() {

View File

@ -1,4 +1,4 @@
var myTextNodeComponent = require("./components/my-text-node");
var myTextNodeComponent = require("./components/my-text-node").default;
module.exports = {
onMount: function() {

View File

@ -1,4 +1,4 @@
var helloComponent = require("./components/hello");
var helloComponent = require("./components/hello").default;
module.exports = {
onMount: function() {

View File

@ -19,7 +19,7 @@ static function handleTestEvent2() {
<app-custom-events onTestEvent(handleTestEvent1) key="customEvents"/>
<app-custom-events
onTestEvent(handleTestEvent2)
channel=`customEvents-${__component.id}`/>
channel=`customEvents-${component.id}`/>
<ul>
<for|color| of=["red", "green", "blue"]>
<li key="colorListItems[]">${color}</li>

View File

@ -6,7 +6,7 @@
<app-custom-events onTestEvent("handleTestEvent1") key="customEvents"/>
<app-custom-events
onTestEvent("handleTestEvent2")
channel=`customEvents-${__component.id}`/>
channel=`customEvents-${component.id}`/>
<ul>
<for|color| of=["red", "green", "blue"]>
<li key="colorListItems[]">${color}</li>

View File

@ -6,7 +6,7 @@
<app-custom-events onTestEvent("handleTestEvent1") key="customEvents"/>
<app-custom-events
onTestEvent("handleTestEvent2")
channel=`customEvents-${__component.id}`/>
channel=`customEvents-${component.id}`/>
<ul>
<for|color| of=["red", "green", "blue"]>
<li key="colorListItems[]">${color}</li>

View File

@ -6,7 +6,7 @@
<app-custom-events onTestEvent("handleTestEvent1") key="customEvents"/>
<app-custom-events
onTestEvent("handleTestEvent2")
channel=`customEvents-${__component.id}`/>
channel=`customEvents-${component.id}`/>
<ul>
<for|color| of=["red", "green", "blue"]>
<li key="colorListItems[]">${color}</li>

View File

@ -2,7 +2,7 @@ var expect = require("chai").expect;
module.exports = function(helpers) {
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 referenceElement = component.getEl("referenceElement");

View File

@ -2,7 +2,7 @@ var expect = require("chai").expect;
module.exports = function(helpers, done) {
var component = helpers.mount(require.resolve("./index.marko"));
var hello = require("./components/hello");
var hello = require("./components/hello").default;
var targetEl = component.getEl("target");
hello

View File

@ -2,7 +2,7 @@ var expect = require("chai").expect;
module.exports = function(helpers) {
var component = helpers.mount(require.resolve("./index.marko"));
var hello = require("./components/hello");
var hello = require("./components/hello").default;
var targetEl = component.getEl("target");
hello.renderSync({ name: "John" }).replace(targetEl);

View File

@ -5,7 +5,7 @@ module.exports = function(helpers) {
var initialCounter = component.getComponent("initialCounter");
var counter = require("./components/app-counter");
var counter = require("./components/app-counter").default;
var renderTarget = component.getEl("renderTarget");
expect(renderTarget.innerHTML).to.contain("Count: 0");

View File

@ -7,5 +7,5 @@ module.exports = function(helpers) {
expect(function() {
component.state.foo = "bar";
}).to.throw(TypeError);
}).to.throw("Cannot add property foo");
};

View File

@ -1,9 +1,9 @@
"use strict";
require("../__util__/test-init");
var autotest = require("../autotest");
var autotest = require("mocha-autotest").default;
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 browserHelpersPath = require.resolve("../__util__/BrowserHelpers");
var testTargetHTML = '<div id="testsTarget"></div><div></div>';
@ -15,11 +15,6 @@ autotest("fixtures", {
hydrate: runHydrateTest
});
autotest("fixtures-deprecated", {
client: runClientTest,
hydrate: runHydrateTest
});
function runClientTest(fixture) {
let test = fixture.test;
let resolve = fixture.resolve;
@ -73,18 +68,14 @@ function runHydrateTest(fixture) {
var browser = createBrowserWithMarko(__dirname, String(html), {
beforeParse(window, browser) {
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);
rootComponent = rootComponent.default || rootComponent;
marko.register(ssrTemplate.meta.id, rootComponent);
components.forEach(function(def) {
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);
});
});
}

View File

@ -1,4 +1,4 @@
var AppHello = require("../app-hello");
var AppHello = require("../app-hello").default;
module.exports = function(input, out) {
var asyncOut = out.beginAsync();

View File

@ -1,5 +1,3 @@
<marko no-browser-rerender />
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,6 +1,6 @@
static {
var markoComponents = require("marko/components");
var componentsTemplate = require("./components.marko");
var componentsTemplate = require("./components.marko").default;
function componentsDataProvider(callback) {
componentsTemplate.renderToString({}, function(err, html, out) {

View File

@ -1,5 +1,5 @@
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() {
var parentNode = document.getElementById("test-result");

View File

@ -0,0 +1,6 @@
module.exports = {
onMount() {
var componentsLookup = window.components || (window.components = {});
componentsLookup["onInput-assign-null-and-return"] = this;
}
};

View File

@ -6,11 +6,6 @@ class {
name: input.name.toUpperCase()
}
}
onMount() {
var componentsLookup = window.components || (window.components = {});
componentsLookup['onInput-assign-null-and-return'] = this;
}
}
<div>

View File

@ -1,5 +1,3 @@
<marko no-browser-rerender />
<!DOCTYPE html>
html lang="en"
head

View File

@ -1,6 +1,6 @@
var expect = require("chai").expect;
it("should allow return", function() {
it.skip("should allow return", function() {
var component = window.components["onInput-return"];
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");
});
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"];
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");
});
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"];
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");
});
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"];
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");
});
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"];
expect(component.input.name).to.equal("HEATHER");

View File

@ -1,5 +1,5 @@
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() {
var serverFooComponent = window.fooComponent;

View File

@ -1,5 +1,3 @@
<marko no-browser-rerender />
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,15 +1,11 @@
var expect = require("chai").expect;
it("should handle ending </script> tag", function(done) {
var ready = require("marko/ready");
ready(function() {
expect(window.fooComponent.state.evil).to.equal(
'</script><script>alert("hello")</script>'
);
expect(window.fooComponent.componentConfig.evil).to.equal(
'</script><script>alert("hello")</script>'
);
done();
});
it("should handle ending </script> tag", function() {
expect(document.readyState).to.equal("complete");
expect(window.fooComponent.state.evil).to.equal(
'</script><script>alert("hello")</script>'
);
expect(window.fooComponent.componentConfig.evil).to.equal(
'</script><script>alert("hello")</script>'
);
});

View File

@ -3,12 +3,11 @@
require("../__util__/test-init");
var path = require("path");
var autotest = require("../autotest");
var autotest = require("mocha-autotest").default;
var asyncTestSuite = require("../__util__/async-test-suite");
var createBrowserWithMarko = require("../__util__/create-marko-jsdom-module");
autotest("fixtures", run);
autotest("fixtures-deprecated", run);
/**
* 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 templateFile = resolve("template.marko");
var template = require(templateFile);
template = template.default || template;
return template
.render({})
.then(function(result) {

View File

@ -1,5 +1,5 @@
module.exports = function(helpers, done) {
var template = require("./template.marko");
var template = require("./template.marko").default;
template.render({ $global: { cspNonce: "abc123" } }, function(err, html) {
if (!/<script.*nonce="abc123".*>/.test(html)) {

View File

@ -2,7 +2,7 @@ var expect = require("chai").expect;
var markoComponents = require("marko/components");
module.exports = function(helpers, done) {
var template = require("./index.marko");
var template = require("./index.marko").default;
template.renderToString({}, function(err, html, out) {
if (err) {

View File

@ -2,10 +2,9 @@
require("../__util__/test-init");
var autotest = require("../autotest");
var autotest = require("mocha-autotest").default;
autotest("fixtures", run);
autotest("fixtures-deprecated", run);
function run(fixture) {
let test = fixture.test;

View File

@ -2,27 +2,24 @@ var Or = 'or';
var And;
var NegateOr;
var NegateAnd = 'negate and';
'else';
'else';
'else';
if (true) {
'else if';
'else if';
} else {
'else';
'else';
}
'negated if';
'negated if';
'negated if';
if (true) {
'negated if';
'negated if';
} else {
'negated else if';
'negated else if';
}
'alternate';
'negated consequent';
'negated consequent';

View File

@ -1,49 +1,25 @@
var Or = 'MARKO_DEBUG' || 'or'
var And = 'MARKO_DEBUG' && 'and'
var NegateOr = !'MARKO_DEBUG' || 'negate or'
var NegateAnd = !'MARKO_DEBUG' && 'negate and'
if ('MARKO_DEBUG') {
'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'
}
var Or = 'or';
var And;
var NegateOr;
var NegateAnd = 'negate and';
'else';
'else';
if (true) {
'negated if'
} else if (!'MARKO_DEBUG') {
'negated else if'
'else if';
} else {
'negated else'
'else';
}
'MARKO_DEBUG' ? 'consequent' : 'alternate'
!'MARKO_DEBUG' ? 'negated consequent' : 'negated alternate'
'negated if';
'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