From 5a2f5b131d6f955853b64e392a48473575b24fd9 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 1 Oct 2021 19:53:21 +0900 Subject: [PATCH 1/3] add #712 reproduction case --- .../20_newsgroups_alt_atheism_51060.txt | 623 ++++++++++++++++++ .../message-compiler/test/tokenizer.test.ts | 19 + packages/vue-i18n-core/src/i18n.ts | 8 + 3 files changed, 650 insertions(+) create mode 100644 packages/message-compiler/test/fixtures/20_newsgroups_alt_atheism_51060.txt diff --git a/packages/message-compiler/test/fixtures/20_newsgroups_alt_atheism_51060.txt b/packages/message-compiler/test/fixtures/20_newsgroups_alt_atheism_51060.txt new file mode 100644 index 000000000..be8decc80 --- /dev/null +++ b/packages/message-compiler/test/fixtures/20_newsgroups_alt_atheism_51060.txt @@ -0,0 +1,623 @@ +This article attempts to provide a general introduction to atheism. Whilst I +have tried to be as neutral as possible regarding contentious issues, you +should always remember that this document represents only one viewpoint. I +would encourage you to read widely and draw your own conclusions; some +relevant books are listed in a companion article. + +To provide a sense of cohesion and progression, I have presented this article +as an imaginary conversation between an atheist and a theist. All the +questions asked by the imaginary theist are questions which have been cropped +up repeatedly on alt.atheism since the newsgroup was created. Some other +frequently asked questions are answered in a companion article. + +Please note that this article is arguably slanted towards answering questions +posed from a Christian viewpoint. This is because the FAQ files reflect +questions which have actually been asked, and it is predominantly Christians +who proselytize on alt.atheism. + +So when I talk of religion, I am talking primarily about religions such as +Christianity, Judaism and Islam, which involve some sort of superhuman divine +being. Much of the discussion will apply to other religions, but some of it +may not. + +"What is atheism?" + +Atheism is characterized by an absence of belief in the existence of God. +Some atheists go further, and believe that God does not exist. The former is +often referred to as the "weak atheist" position, and the latter as "strong +atheism". + +It is important to note the difference between these two positions. "Weak +atheism" is simple scepticism; disbelief in the existence of God. "Strong +atheism" is a positive belief that God does not exist. Please do not +fall into the trap of assuming that all atheists are "strong atheists". + +Some atheists believe in the non-existence of all Gods; others limit their +atheism to specific Gods, such as the Christian God, rather than making +flat-out denials. + +"But isn't disbelieving in God the same thing as believing he doesn't exist?" + +Definitely not. Disbelief in a proposition means that one does not believe +it to be true. Not believing that something is true is not equivalent to +believing that it is false; one may simply have no idea whether it is true or +not. Which brings us to agnosticism. + +"What is agnosticism then?" + +The term 'agnosticism' was coined by Professor Huxley at a meeting of the +Metaphysical Society in 1876. He defined an agnostic as someone who +disclaimed ("strong") atheism and believed that the ultimate origin of things +must be some cause unknown and unknowable. + +Thus an agnostic is someone who believes that we do not and cannot know for +sure whether God exists. + +Words are slippery things, and language is inexact. Beware of assuming that +you can work out someone's philosophical point of view simply from the fact +that she calls herself an atheist or an agnostic. For example, many people +use agnosticism to mean "weak atheism", and use the word "atheism" only when +referring to "strong atheism". + +Beware also that because the word "atheist" has so many shades of meaning, it +is very difficult to generalize about atheists. About all you can say for +sure is that atheists don't believe in God. For example, it certainly isn't +the case that all atheists believe that science is the best way to find out +about the universe. + +"So what is the philosophical justification or basis for atheism?" + +There are many philosophical justifications for atheism. To find out why a +particular person chooses to be an atheist, it's best to ask her. + +Many atheists feel that the idea of God as presented by the major religions +is essentially self-contradictory, and that it is logically impossible that +such a God could exist. Others are atheists through scepticism, because they +see no evidence that God exists. + +"But isn't it impossible to prove the non-existence of something?" + +There are many counter-examples to such a statement. For example, it is +quite simple to prove that there does not exist a prime number larger than +all other prime numbers. Of course, this deals with well-defined objects +obeying well-defined rules. Whether Gods or universes are similarly +well-defined is a matter for debate. + +However, assuming for the moment that the existence of a God is not provably +impossible, there are still subtle reasons for assuming the non-existence of +God. If we assume that something does not exist, it is always possible to +show that this assumption is invalid by finding a single counter-example. + +If on the other hand we assume that something does exist, and if the thing in +question is not provably impossible, showing that the assumption is invalid +may require an exhaustive search of all possible places where such a thing +might be found, to show that it isn't there. Such an exhaustive search is +often impractical or impossible. There is no such problem with largest +primes, because we can prove that they don't exist. + +Therefore it is generally accepted that we must assume things do not exist +unless we have evidence that they do. Even theists follow this rule most of +the time; they don't believe in unicorns, even though they can't conclusively +prove that no unicorns exist anywhere. + +To assume that God exists is to make an assumption which probably cannot be +tested. We cannot make an exhaustive search of everywhere God might be to +prove that he doesn't exist anywhere. So the sceptical atheist assumes by +default that God does not exist, since that is an assumption we can test. + +Those who profess strong atheism usually do not claim that no sort of God +exists; instead, they generally restrict their claims so as to cover +varieties of God described by followers of various religions. So whilst it +may be impossible to prove conclusively that no God exists, it may be +possible to prove that (say) a God as described by a particular religious +book does not exist. It may even be possible to prove that no God described +by any present-day religion exists. + +In practice, believing that no God described by any religion exists is very +close to believing that no God exists. However, it is sufficiently different +that counter-arguments based on the impossibility of disproving every kind of +God are not really applicable. + +"But what if God is essentially non-detectable?" + +If God interacts with our universe in any way, the effects of his interaction +must be measurable. Hence his interaction with our universe must be +detectable. + +If God is essentially non-detectable, it must therefore be the case that he +does not interact with our universe in any way. Many atheists would argue +that if God does not interact with our universe at all, it is of no +importance whether he exists or not. + +If the Bible is to be believed, God was easily detectable by the Israelites. +Surely he should still be detectable today? + +Note that I am not demanding that God interact in a scientifically +verifiable, physical way. It must surely be possible to perceive some +effect caused by his presence, though; otherwise, how can I distinguish him +from all the other things that don't exist? + +"OK, you may think there's a philosophical justification for atheism, but + isn't it still a religious belief?" + +One of the most common pastimes in philosophical discussion is "the +redefinition game". The cynical view of this game is as follows: + +Person A begins by making a contentious statement. When person B points out +that it can't be true, person A gradually re-defines the words he used in the +statement until he arrives at something person B is prepared to accept. He +then records the statement, along with the fact that person B has agreed to +it, and continues. Eventually A uses the statement as an "agreed fact", but +uses his original definitions of all the words in it rather than the obscure +redefinitions originally needed to get B to agree to it. Rather than be seen +to be apparently inconsistent, B will tend to play along. + +The point of this digression is that the answer to the question "Isn't +atheism a religious belief?" depends crucially upon what is meant by +"religious". "Religion" is generally characterized by belief in a superhuman +controlling power -- especially in some sort of God -- and by faith and +worship. + +[ It's worth pointing out in passing that some varieties of Buddhism are not + "religion" according to such a definition. ] + +Atheism is certainly not a belief in any sort of superhuman power, nor is it +categorized by worship in any meaningful sense. Widening the definition of +"religious" to encompass atheism tends to result in many other aspects of +human behaviour suddenly becoming classed as "religious" as well -- such as +science, politics, and watching TV. + +"OK, so it's not a religion. But surely belief in atheism (or science) is + still just an act of faith, like religion is?" + +Firstly, it's not entirely clear that sceptical atheism is something one +actually believes in. + +Secondly, it is necessary to adopt a number of core beliefs or assumptions to +make some sort of sense out of the sensory data we experience. Most atheists +try to adopt as few core beliefs as possible; and even those are subject to +questioning if experience throws them into doubt. + +Science has a number of core assumptions. For example, it is generally +assumed that the laws of physics are the same for all observers. These are +the sort of core assumptions atheists make. If such basic ideas are called +"acts of faith", then almost everything we know must be said to be based on +acts of faith, and the term loses its meaning. + +Faith is more often used to refer to complete, certain belief in something. +According to such a definition, atheism and science are certainly not acts of +faith. Of course, individual atheists or scientists can be as dogmatic as +religious followers when claiming that something is "certain". This is not a +general tendency, however; there are many atheists who would be reluctant to +state with certainty that the universe exists. + +Faith is also used to refer to belief without supporting evidence or proof. +Sceptical atheism certainly doesn't fit that definition, as sceptical atheism +has no beliefs. Strong atheism is closer, but still doesn't really match, as +even the most dogmatic atheist will tend to refer to experimental data (or +the lack of it) when asserting that God does not exist. + +"If atheism is not religious, surely it's anti-religious?" + +It is an unfortunate human tendency to label everyone as either "for" or +"against", "friend" or "enemy". The truth is not so clear-cut. + +Atheism is the position that runs logically counter to theism; in that sense, +it can be said to be "anti-religion". However, when religious believers +speak of atheists being "anti-religious" they usually mean that the atheists +have some sort of antipathy or hatred towards theists. + +This categorization of atheists as hostile towards religion is quite unfair. +Atheist attitudes towards theists in fact cover a broad spectrum. + +Most atheists take a "live and let live" attitude. Unless questioned, they +will not usually mention their atheism, except perhaps to close friends. Of +course, this may be in part because atheism is not "socially acceptable" in +many countries. + +A few atheists are quite anti-religious, and may even try to "convert" others +when possible. Historically, such anti-religious atheists have made little +impact on society outside the Eastern Bloc countries. + +(To digress slightly: the Soviet Union was originally dedicated to separation +of church and state, just like the USA. Soviet citizens were legally free to +worship as they wished. The institution of "state atheism" came about when +Stalin took control of the Soviet Union and tried to destroy the churches in +order to gain complete power over the population.) + +Some atheists are quite vocal about their beliefs, but only where they see +religion encroaching on matters which are not its business -- for example, +the government of the USA. Such individuals are usually concerned that +church and state should remain separate. + +"But if you don't allow religion to have a say in the running of the state, + surely that's the same as state atheism?" + +The principle of the separation of church and state is that the state shall +not legislate concerning matters of religious belief. In particular, it +means not only that the state cannot promote one religion at the expense of +another, but also that it cannot promote any belief which is religious in +nature. + +Religions can still have a say in discussion of purely secular matters. For +example, religious believers have historically been responsible for +encouraging many political reforms. Even today, many organizations +campaigning for an increase in spending on foreign aid are founded as +religious campaigns. So long as they campaign concerning secular matters, +and so long as they do not discriminate on religious grounds, most atheists +are quite happy to see them have their say. + +"What about prayer in schools? If there's no God, why do you care if people + pray?" + +Because people who do pray are voters and lawmakers, and tend to do things +that those who don't pray can't just ignore. Also, Christian prayer in +schools is intimidating to non-Christians, even if they are told that they +need not join in. The diversity of religious and non-religious belief means +that it is impossible to formulate a meaningful prayer that will be +acceptable to all those present at any public event. + +Also, non-prayers tend to have friends and family who pray. It is reasonable +to care about friends and family wasting their time, even without other +motives. + +"You mentioned Christians who campaign for increased foreign aid. What about + atheists? Why aren't there any atheist charities or hospitals? Don't + atheists object to the religious charities?" + +There are many charities without religious purpose that atheists can +contribute to. Some atheists contribute to religious charities as well, for +the sake of the practical good they do. Some atheists even do voluntary work +for charities founded on a theistic basis. + +Most atheists seem to feel that atheism isn't worth shouting about in +connection with charity. To them, atheism is just a simple, obvious everyday +matter, and so is charity. Many feel that it's somewhat cheap, not to say +self-righteous, to use simple charity as an excuse to plug a particular set +of religious beliefs. + +To "weak" atheists, building a hospital to say "I do not believe in God" is a +rather strange idea; it's rather like holding a party to say "Today is not my +birthday". Why the fuss? Atheism is rarely evangelical. + +"You said atheism isn't anti-religious. But is it perhaps a backlash against + one's upbringing, a way of rebelling?" + +Perhaps it is, for some. But many people have parents who do not attempt to +force any religious (or atheist) ideas upon them, and many of those people +choose to call themselves atheists. + +It's also doubtless the case that some religious people chose religion as a +backlash against an atheist upbringing, as a way of being different. On the +other hand, many people choose religion as a way of conforming to the +expectations of others. + +On the whole, we can't conclude much about whether atheism or religion are +backlash or conformism; although in general, people have a tendency to go +along with a group rather than act or think independently. + +"How do atheists differ from religious people?" + +They don't believe in God. That's all there is to it. + +Atheists may listen to heavy metal -- backwards, even -- or they may prefer a +Verdi Requiem, even if they know the words. They may wear Hawaiian shirts, +they may dress all in black, they may even wear orange robes. (Many +Buddhists lack a belief in any sort of God.) Some atheists even carry a copy +of the Bible around -- for arguing against, of course! + +Whoever you are, the chances are you have met several atheists without +realising it. Atheists are usually unexceptional in behaviour and +appearance. + +"Unexceptional? But aren't atheists less moral than religious people?" + +That depends. If you define morality as obedience to God, then of course +atheists are less moral as they don't obey any God. But usually when one +talks of morality, one talks of what is acceptable ("right") and unacceptable +("wrong") behaviour within society. + +Humans are social animals, and to be maximally successful they must +co-operate with each other. This is a good enough reason to discourage most +atheists from "anti-social" or "immoral" behaviour, purely for the purposes +of self-preservation. + +Many atheists behave in a "moral" or "compassionate" way simply because they +feel a natural tendency to empathize with other humans. So why do they care +what happens to others? They don't know, they simply are that way. + +Naturally, there are some people who behave "immorally" and try to use +atheism to justify their actions. However, there are equally many people who +behave "immorally" and then try to use religious beliefs to justify their +actions. For example: + + "Here is a trustworthy saying that deserves full acceptance: Jesus Christ + came into the world to save sinners... But for that very reason, I was + shown mercy so that in me... Jesus Christ might display His unlimited + patience as an example for those who would believe in him and receive + eternal life. Now to the king eternal, immortal, invisible, the only God, + be honor and glory forever and ever." + +The above quote is from a statement made to the court on February 17th 1992 +by Jeffrey Dahmer, the notorious cannibal serial killer of Milwaukee, +Wisconsin. It seems that for every atheist mass-murderer, there is a +religious mass-murderer. But what of more trivial morality? + + A survey conducted by the Roper Organization found that behavior + deteriorated after "born again" experiences. While only 4% of respondents + said they had driven intoxicated before being "born again," 12% had done + so after conversion. Similarly, 5% had used illegal drugs before + conversion, 9% after. Two percent admitted to engaging in illicit sex + before salvation; 5% after. + ["Freethought Today", September 1991, p. 12.] + +So it seems that at best, religion does not have a monopoly on moral +behaviour. + +"Is there such a thing as atheist morality?" + +If you mean "Is there such a thing as morality for atheists?", then the +answer is yes, as explained above. Many atheists have ideas about morality +which are at least as strong as those held by religious people. + +If you mean "Does atheism have a characteristic moral code?", then the answer +is no. Atheism by itself does not imply anything much about how a person +will behave. Most atheists follow many of the same "moral rules" as theists, +but for different reasons. Atheists view morality as something created by +humans, according to the way humans feel the world 'ought' to work, rather +than seeing it as a set of rules decreed by a supernatural being. + +"Then aren't atheists just theists who are denying God?" + +A study by the Freedom From Religion Foundation found that over 90% of the +atheists who responded became atheists because religion did not work for +them. They had found that religious beliefs were fundamentally incompatible +with what they observed around them. + +Atheists are not unbelievers through ignorance or denial; they are +unbelievers through choice. The vast majority of them have spent time +studying one or more religions, sometimes in very great depth. They have +made a careful and considered decision to reject religious beliefs. + +This decision may, of course, be an inevitable consequence of that +individual's personality. For a naturally sceptical person, the choice +of atheism is often the only one that makes sense, and hence the only +choice that person can honestly make. + +"But don't atheists want to believe in God?" + +Atheists live their lives as though there is nobody watching over them. Many +of them have no desire to be watched over, no matter how good-natured the +"Big Brother" figure might be. + +Some atheists would like to be able to believe in God -- but so what? Should +one believe things merely because one wants them to be true? The risks of +such an approach should be obvious. Atheists often decide that wanting to +believe something is not enough; there must be evidence for the belief. + +"But of course atheists see no evidence for the existence of God -- they are + unwilling in their souls to see!" + +Many, if not most atheists were previously religious. As has been explained +above, the vast majority have seriously considered the possibility that God +exists. Many atheists have spent time in prayer trying to reach God. + +Of course, it is true that some atheists lack an open mind; but assuming that +all atheists are biased and insincere is offensive and closed-minded. +Comments such as "Of course God is there, you just aren't looking properly" +are likely to be viewed as patronizing. + +Certainly, if you wish to engage in philosophical debate with atheists it is +vital that you give them the benefit of the doubt and assume that they are +being sincere if they say that they have searched for God. If you are not +willing to believe that they are basically telling the truth, debate is +futile. + +"Isn't the whole of life completely pointless to an atheist?" + +Many atheists live a purposeful life. They decide what they think gives +meaning to life, and they pursue those goals. They try to make their lives +count, not by wishing for eternal life, but by having an influence on other +people who will live on. For example, an atheist may dedicate his life to +political reform, in the hope of leaving his mark on history. + +It is a natural human tendency to look for "meaning" or "purpose" in random +events. However, it is by no means obvious that "life" is the sort of thing +that has a "meaning". + +To put it another way, not everything which looks like a question is actually +a sensible thing to ask. Some atheists believe that asking "What is the +meaning of life?" is as silly as asking "What is the meaning of a cup of +coffee?". They believe that life has no purpose or meaning, it just is. + +"So how do atheists find comfort in time of danger?" + +There are many ways of obtaining comfort; from family, friends, or even pets. +Or on a less spiritual level, from food or drink or TV. + +That may sound rather an empty and vulnerable way to face danger, but so +what? Should individuals believe in things because they are comforting, or +should they face reality no matter how harsh it might be? + +In the end, it's a decision for the individual concerned. Most atheists are +unable to believe something they would not otherwise believe merely because +it makes them feel comfortable. They put truth before comfort, and consider +that if searching for truth sometimes makes them feel unhappy, that's just +hard luck. + +"Don't atheists worry that they might suddenly be shown to be wrong?" + +The short answer is "No, do you?" + +Many atheists have been atheists for years. They have encountered many +arguments and much supposed evidence for the existence of God, but they have +found all of it to be invalid or inconclusive. + +Thousands of years of religious belief haven't resulted in any good proof of +the existence of God. Atheists therefore tend to feel that they are unlikely +to be proved wrong in the immediate future, and they stop worrying about it. + +"So why should theists question their beliefs? Don't the same arguments + apply?" + +No, because the beliefs being questioned are not similar. Weak atheism is +the sceptical "default position" to take; it asserts nothing. Strong atheism +is a negative belief. Theism is a very strong positive belief. + +Atheists sometimes also argue that theists should question their beliefs +because of the very real harm they can cause -- not just to the believers, +but to everyone else. + +"What sort of harm?" + +Religion represents a huge financial and work burden on mankind. It's not +just a matter of religious believers wasting their money on church buildings; +think of all the time and effort spent building churches, praying, and so on. +Imagine how that effort could be better spent. + +Many theists believe in miracle healing. There have been plenty of instances +of ill people being "healed" by a priest, ceasing to take the medicines +prescribed to them by doctors, and dying as a result. Some theists have died +because they have refused blood transfusions on religious grounds. + +It is arguable that the Catholic Church's opposition to birth control -- and +condoms in particular -- is increasing the problem of overpopulation in many +third-world countries and contributing to the spread of AIDS world-wide. + +Religious believers have been known to murder their children rather than +allow their children to become atheists or marry someone of a different +religion. + +"Those weren't REAL believers. They just claimed to be believers as some + sort of excuse." + +What makes a real believer? There are so many One True Religions it's hard +to tell. Look at Christianity: there are many competing groups, all +convinced that they are the only true Christians. Sometimes they even fight +and kill each other. How is an atheist supposed to decide who's a REAL +Christian and who isn't, when even the major Christian churches like the +Catholic Church and the Church of England can't decide amongst themselves? + +In the end, most atheists take a pragmatic view, and decide that anyone who +calls himself a Christian, and uses Christian belief or dogma to justify his +actions, should be considered a Christian. Maybe some of those Christians +are just perverting Christian teaching for their own ends -- but surely if +the Bible can be so readily used to support un-Christian acts it can't be +much of a moral code? If the Bible is the word of God, why couldn't he have +made it less easy to misinterpret? And how do you know that your beliefs +aren't a perversion of what your God intended? + +If there is no single unambiguous interpretation of the Bible, then why +should an atheist take one interpretation over another just on your say-so? +Sorry, but if someone claims that he believes in Jesus and that he murdered +others because Jesus and the Bible told him to do so, we must call him a +Christian. + +"Obviously those extreme sorts of beliefs should be questioned. But since + nobody has ever proved that God does not exist, it must be very unlikely + that more basic religious beliefs, shared by all faiths, are nonsense." + +That does not hold, because as was pointed out at the start of this dialogue, +positive assertions concerning the existence of entities are inherently much +harder to disprove than negative ones. Nobody has ever proved that unicorns +don't exist, but that doesn't make it unlikely that they are myths. + +It is therefore much more valid to hold a negative assertion by default than +it is to hold a positive assertion by default. Of course, "weak" atheists +would argue that asserting nothing is better still. + +"Well, if atheism's so great, why are there so many theists?" + +Unfortunately, the popularity of a belief has little to do with how "correct" +it is, or whether it "works"; consider how many people believe in astrology, +graphology, and other pseudo-sciences. + +Many atheists feel that it is simply a human weakness to want to believe in +gods. Certainly in many primitive human societies, religion allows the +people to deal with phenomena that they do not adequately understand. + +Of course, there's more to religion than that. In the industrialized world, +we find people believing in religious explanations of phenomena even when +there are perfectly adequate natural explanations. Religion may have started +as a means of attempting to explain the world, but nowadays it serves other +purposes as well. + +"But so many cultures have developed religions. Surely that must say + something?" + +Not really. Most religions are only superficially similar; for example, it's +worth remembering that religions such as Buddhism and Taoism lack any sort of +concept of God in the Christian sense. + +Of course, most religions are quick to denounce competing religions, so it's +rather odd to use one religion to try and justify another. + +"What about all the famous scientists and philosophers who have concluded + that God exists?" + +For every scientist or philosopher who believes in a god, there is one who +does not. Besides, as has already been pointed out, the truth of a belief is +not determined by how many people believe it. Also, it is important to +realize that atheists do not view famous scientists or philosophers in the +same way that theists view their religious leaders. + +A famous scientist is only human; she may be an expert in some fields, but +when she talks about other matters her words carry no special weight. Many +respected scientists have made themselves look foolish by speaking on +subjects which lie outside their fields of expertise. + +"So are you really saying that widespread belief in religion indicates + nothing?" + +Not entirely. It certainly indicates that the religion in question has +properties which have helped it so spread so far. + +The theory of memetics talks of "memes" -- sets of ideas which can propagate +themselves between human minds, by analogy with genes. Some atheists view +religions as sets of particularly successful parasitic memes, which spread by +encouraging their hosts to convert others. Some memes avoid destruction by +discouraging believers from questioning doctrine, or by using peer pressure +to keep one-time believers from admitting that they were mistaken. Some +religious memes even encourage their hosts to destroy hosts controlled by +other memes. + +Of course, in the memetic view there is no particular virtue associated with +successful propagation of a meme. Religion is not a good thing because of +the number of people who believe it, any more than a disease is a good thing +because of the number of people who have caught it. + +"Even if religion is not entirely true, at least it puts across important + messages. What are the fundamental messages of atheism?" + +There are many important ideas atheists promote. The following are just a +few of them; don't be surprised to see ideas which are also present in some +religions. + + There is more to moral behaviour than mindlessly following rules. + + Be especially sceptical of positive claims. + + If you want your life to have some sort of meaning, it's up to you to + find it. + + Search for what is true, even if it makes you uncomfortable. + + Make the most of your life, as it's probably the only one you'll have. + + It's no good relying on some external power to change you; you must change + yourself. + + Just because something's popular doesn't mean it's good. + + If you must assume something, assume something it's easy to test. + + Don't believe things just because you want them to be true. + +and finally (and most importantly): + + All beliefs should be open to question. + +Thanks for taking the time to read this article. + + +mathew diff --git a/packages/message-compiler/test/tokenizer.test.ts b/packages/message-compiler/test/tokenizer.test.ts index 55daeebe1..5d5c3200b 100644 --- a/packages/message-compiler/test/tokenizer.test.ts +++ b/packages/message-compiler/test/tokenizer.test.ts @@ -1,6 +1,8 @@ import { parse } from '../src/tokenizer' import { TokenizeOptions } from '../src/options' import { CompileError } from '../src/errors' +import path from 'path' +import fs from 'fs/promises' test('token analysis', () => { const cases = [ @@ -98,3 +100,20 @@ test('token analysis', () => { } } }) + +describe('edge cases', () => { + test('long text', async () => { + const data = await fs.readFile( + path.join(__dirname, './fixtures/20_newsgroups_alt_atheism_51060.txt'), + 'utf8' + ) + let err = null + try { + const tokens = parse(data) + } catch (e) { + console.error(e) + err = e + } + expect(err).toEqual(null) + }) +}) diff --git a/packages/vue-i18n-core/src/i18n.ts b/packages/vue-i18n-core/src/i18n.ts index fb787913a..59f71e68e 100644 --- a/packages/vue-i18n-core/src/i18n.ts +++ b/packages/vue-i18n-core/src/i18n.ts @@ -568,6 +568,14 @@ export function createI18n(options: any = {}, VueI18nLegacy?: any): any { if (version !== 2) { throw createI18nError(I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY) } + if (!Vue.prototype.hasOwnProperty('$i18n')) { + Object.defineProperty(Vue.prototype, '$i18n', { + get() { + return this._i18n + } + }) + } + Vue.mixin(defineMixinBridge(i18n, _legacyVueI18n)) } }) From 3729ee00b30353349b65e1f29d172d62e26ea7b8 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 1 Oct 2021 19:55:05 +0900 Subject: [PATCH 2/3] remove unnecesary code --- packages/vue-i18n-core/src/i18n.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/vue-i18n-core/src/i18n.ts b/packages/vue-i18n-core/src/i18n.ts index 59f71e68e..18d3f30f1 100644 --- a/packages/vue-i18n-core/src/i18n.ts +++ b/packages/vue-i18n-core/src/i18n.ts @@ -568,13 +568,6 @@ export function createI18n(options: any = {}, VueI18nLegacy?: any): any { if (version !== 2) { throw createI18nError(I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY) } - if (!Vue.prototype.hasOwnProperty('$i18n')) { - Object.defineProperty(Vue.prototype, '$i18n', { - get() { - return this._i18n - } - }) - } Vue.mixin(defineMixinBridge(i18n, _legacyVueI18n)) } From 7fd8cae84117e97a655b76e7f3aa98a729d38b5f Mon Sep 17 00:00:00 2001 From: Fabian Kranewitter Date: Fri, 1 Oct 2021 19:43:03 +0200 Subject: [PATCH 3/3] Rewrite readText as an iterative version Fix warning in test --- packages/message-compiler/src/tokenizer.ts | 19 +++++++------------ .../message-compiler/test/tokenizer.test.ts | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/message-compiler/src/tokenizer.ts b/packages/message-compiler/src/tokenizer.ts index 344c662ce..6f76ca1fb 100644 --- a/packages/message-compiler/src/tokenizer.ts +++ b/packages/message-compiler/src/tokenizer.ts @@ -438,45 +438,40 @@ export function createTokenizer( } function readText(scnr: Scanner): string { - const fn = (buf: string): string => { + let buf = '' + while (true) { const ch = scnr.currentChar() if ( ch === TokenChars.BraceLeft || ch === TokenChars.BraceRight || ch === TokenChars.LinkedAlias || + ch === TokenChars.Pipe || !ch ) { - return buf + break } else if (ch === TokenChars.Modulo) { if (isTextStart(scnr)) { buf += ch scnr.next() - return fn(buf) } else { - return buf + break } - } else if (ch === TokenChars.Pipe) { - return buf } else if (ch === SPACE || ch === NEW_LINE) { if (isTextStart(scnr)) { buf += ch scnr.next() - return fn(buf) } else if (isPluralStart(scnr)) { - return buf + break } else { buf += ch scnr.next() - return fn(buf) } } else { buf += ch scnr.next() - return fn(buf) } } - - return fn('') + return buf } function readNamedIdentifier(scnr: Scanner): string { diff --git a/packages/message-compiler/test/tokenizer.test.ts b/packages/message-compiler/test/tokenizer.test.ts index 5d5c3200b..62f5d6820 100644 --- a/packages/message-compiler/test/tokenizer.test.ts +++ b/packages/message-compiler/test/tokenizer.test.ts @@ -2,7 +2,7 @@ import { parse } from '../src/tokenizer' import { TokenizeOptions } from '../src/options' import { CompileError } from '../src/errors' import path from 'path' -import fs from 'fs/promises' +import { promises as fs } from 'fs' test('token analysis', () => { const cases = [ @@ -109,7 +109,7 @@ describe('edge cases', () => { ) let err = null try { - const tokens = parse(data) + parse(data) } catch (e) { console.error(e) err = e