82 lines
1.6 KiB
JavaScript
82 lines
1.6 KiB
JavaScript
|
|
/*
|
||
|
|
|
||
|
|
Copyright (c) 2020, 2023, The Unified Company.
|
||
|
|
|
||
|
|
This code is part of Unify.
|
||
|
|
|
||
|
|
This program is free software; you can redistribute it and/or modify
|
||
|
|
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
|
||
|
|
as published by the ESA.
|
||
|
|
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
|
||
|
|
|
||
|
|
https://unifyjs.org
|
||
|
|
|
||
|
|
*/
|
||
|
|
|
||
|
|
export default class multiExtender{
|
||
|
|
|
||
|
|
processExtendLine( stripped, extendsIndex, lines, i ) {
|
||
|
|
|
||
|
|
var bodyOpenIndex = stripped.indexOf("{")
|
||
|
|
|
||
|
|
if( bodyOpenIndex == -1 ) {
|
||
|
|
|
||
|
|
var extendArgumentsString = stripped.slice( extendsIndex + 7 )
|
||
|
|
|
||
|
|
} else {
|
||
|
|
|
||
|
|
var extendArgumentsString = stripped.slice( extendsIndex + 7, bodyOpenIndex )
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
var extendArguments = extendArgumentsString.split(",");
|
||
|
|
|
||
|
|
extendArguments = extendArguments.map( str => str.replace(/\s/g, '') );
|
||
|
|
|
||
|
|
var newArguments = " extender(" + extendArguments.join(",") + ")";
|
||
|
|
|
||
|
|
if( extendArguments.length > 1 ) {
|
||
|
|
|
||
|
|
lines[i] = lines[i].replace(extendArgumentsString, newArguments)
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
processLine( lines, i ) {
|
||
|
|
|
||
|
|
var stripped = lines[i].replaceAll("\t", " ");
|
||
|
|
|
||
|
|
var extendsIndex = stripped.indexOf("extends")
|
||
|
|
|
||
|
|
var lineWidth = stripped.length;
|
||
|
|
|
||
|
|
if( extendsIndex != -1 ) {
|
||
|
|
|
||
|
|
this.processExtendLine( stripped, extendsIndex, lines, i );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
enableMultiExtend( source, depth ) {
|
||
|
|
|
||
|
|
source = source.replaceAll("\r", "\n");
|
||
|
|
|
||
|
|
var lines = source.split("\n");
|
||
|
|
|
||
|
|
for (var i = 0; i < lines.length; i++) {
|
||
|
|
|
||
|
|
this.processLine( lines, i );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
var body = "\n\n";
|
||
|
|
|
||
|
|
body += lines.join("\n");
|
||
|
|
|
||
|
|
return body;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|